Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-594

[Bug]: InvalidOperationException defining Schema configuration property

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • Q4-22FY
    • Affects Version/s: None
    • Component/s: None

      What happened?

      Randomly, while settings Schema property of RealmConfiguration using new Type[] { } array value throws an InvalidOperationException with the message:

      System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.

      NOTE: I create a realm instance everytime I need to read or write a value in my app. My application is multi-threaded, and notify the UI of the changes over the entities is not a requirement. The read and the writes must be auto-contained.

      There is a working thread that constantly read bluetooth objects and read the DB every 500 ms to identify them.

      Repro steps

      Launch the app, create a RealmConfiguration instance and apply a schema using the Schema property.

      Version

      10.6.0 dotnet

      What SDK flavour are you using?

      Local Database only

      What type of application is this?

      Xamarin

      Client OS and version

      Android 7, Xamarin.Android 11.4.0.5

      Code snippets

      Realm instance initialization method:

      realmConfiguration = new RealmConfiguration(DefaultRealmFilename);               
      realmConfiguration.SchemaVersion = CurrentSchemaVersion;
      realmConfiguration.MigrationCallback = this.MigrationCallback;
      
        // realmConfiguration.ObjectClasses = new Type[] { }  seems deprecated. 
        // use Schema instead.
      
        try
        {
            realmConfiguration.Schema = new Type[]
            {
            typeof(TableA),
            typeof(TableB),
            };
        }
      
      // this code is never reached, the exception throws on the schema part.
      
       try
        {
            this.realm = Realm.GetInstance(this.realmConfiguration);
      #if HEAVY_VERBOSE_MODE
            if (SynchronizationContext.Current != null)
            {
                Logger.Debug("SyncContext is not null.");
            }
            else
                Logger.Debug("SyncContext is null.");
      #endif
        }
        catch(RealmMigrationNeededException realmMigrationException)
        {
            Logger.Warning("A migration is needed on current app version.");
            Logger.Warning(realmMigrationException.ToString());
            migrationException = realmMigrationException;
            requireMigration = true;                
        }
      
      

      For every write or read, the realm object is instantiated using:

      IStorageProviderContext storageProviderContext = null;
      
      try
      {
          if (StorageManager.Current != null)
              storageProviderContext = SmartlockStorageManager.Current.CreateProviderInstance();
      }
      catch(Exception exc)
      {
          Logger.Error(exc);
      }            
      
      try
      {                
          using (storageProviderContext)
          {
              if (storageProviderContext != null)
              {
                  objectsCount = storageProviderContext.KnownObjects.Count;
                  locatonsCount = storageProviderContext.Locations.Count;
              }
          }
      }
      catch (Exception exc)
      {
          Logger.Error(exc);
      }
      
      

      Stacktrace of the exception/crash you're getting

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) [0x00105] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:437 
        at System.Collections.Generic.Dictionary`2[TKey,TValue].TryGetValue (TKey key, TValue& value) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:888 
        at Realms.Schema.ObjectSchema.FromType (System.Type type) [0x0000b] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Schema\ObjectSchema.cs:126 
        at Realms.Schema.RealmSchema+Builder.Add (System.Type type) [0x0000b] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Schema\RealmSchema.cs:341 
        at Realms.Schema.RealmSchema+Builder..ctor (System.Collections.Generic.IEnumerable`1[T] types) [0x00021] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Schema\RealmSchema.cs:273 
        at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config) [0x0000a] in D:\a\realm-dotnet\realm-dotnet\11-01 00:50:26.989 V/mono-stdout(30354):   at Realms.Schema.RealmSchema.op_Implicit (System.Collections.Generic.HashSet`1[T] objects) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Schema\RealmSchema.cs:245 
        at Realms.Schema.RealmSchema+<>c.<.cctor>b__25_0 () [0x00090] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Schema\RealmSchema.cs:66 
        at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x0001c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:327 
      --- End of stack trace from previous location where exception was thrown ---
        at System.Lazy`1[T].CreateValue () [0x0007e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:435 
        at System.Lazy`1[T].get_Value () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509 
        at Realms.Schema.RealmSchema.get_Default () [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Schema\RealmSchema.cs:99 
        at Realms.RealmConfigurationBase.GetSchema () [0x0001d] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Configurations\RealmConfigurationBase.cs:241 
        at Realms.RealmConfiguration.CreateRealm () [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Configurations\RealmConfiguration.cs:126 
        at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config) [0x0000a] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Realm.cs:83
      

      Relevant log output

      No response

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: