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

[Bug]: BsonSerializationException when accessing realm offline.

      What happened?

      My application uses Realm Sync, and accesses the realm by creating a SyncConfiguration and then calling GetInstance() on it. This works fine when the application is online, but if the app is offline, the SyncConfiguration constructor throws the following exception

       **System.TypeInitializationException:** 'The type initializer for 'Realms.Helpers.SerializationHelper' threw an exception.'
      
      [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Realms.Helpers.SerializationHelper' threw an exception. ---> MongoDB.Bson.BsonSerializationException: There is already a serializer registered for type DateTimeOffset.
      [mono-rt]   at MongoDB.Bson.Serialization.BsonSerializerRegistry.RegisterSerializer (System.Type type, MongoDB.Bson.Serialization.IBsonSerializer serializer) [0x000a5] in <3323b1fef8254a9a8e9fe351c6349ba3>:0 
      [mono-rt]   at MongoDB.Bson.Serialization.BsonSerializer.RegisterSerializer (System.Type type, MongoDB.Bson.Serialization.IBsonSerializer serializer) [0x00000] in <3323b1fef8254a9a8e9fe351c6349ba3>:0 
      [mono-rt]   at MongoDB.Bson.Serialization.BsonSerializer.RegisterSerializer[T] (MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] serializer) [0x00000] in <3323b1fef8254a9a8e9fe351c6349ba3>:0 
      [mono-rt]   at Realms.Helpers.SerializationHelper..cctor () [0x0002f] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Helpers\SerializationHelper.cs:42 
      

      Repro steps

      1) Sign in a Realm Sync user when online.
      2) Turn the phone's internet off and redeploy the app.
      3) Get the last logged in user.
      4) Create a sync configuration object as follows:
      SyncConfiguration config = new SyncConfiguration("PUBLIC", _realmUser);
      (This is the stage where the exception is thrown)

      Version

      10.7.1

      What SDK flavour are you using?

      MongoDB Realm (i.e. Sync, auth, functions)

      What type of application is this?

      Xamarin

      Client OS and version

      Android Version 10

      Code snippets

      No response

      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
      **System.TypeInitializationException:** 'The type initializer for 'Realms.Helpers.SerializationHelper' threw an exception.'
      
      [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Realms.Helpers.SerializationHelper' threw an exception. ---> MongoDB.Bson.BsonSerializationException: There is already a serializer registered for type DateTimeOffset.
      [mono-rt]   at MongoDB.Bson.Serialization.BsonSerializerRegistry.RegisterSerializer (System.Type type, MongoDB.Bson.Serialization.IBsonSerializer serializer) [0x000a5] in <3323b1fef8254a9a8e9fe351c6349ba3>:0 
      [mono-rt]   at MongoDB.Bson.Serialization.BsonSerializer.RegisterSerializer (System.Type type, MongoDB.Bson.Serialization.IBsonSerializer serializer) [0x00000] in <3323b1fef8254a9a8e9fe351c6349ba3>:0 
      [mono-rt]   at MongoDB.Bson.Serialization.BsonSerializer.RegisterSerializer[T] (MongoDB.Bson.Serialization.IBsonSerializer`1[TValue] serializer) [0x00000] in <3323b1fef8254a9a8e9fe351c6349ba3>:0 
      [mono-rt]   at Realms.Helpers.SerializationHelper..cctor () [0x0002f] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Helpers\SerializationHelper.cs:42 
      [mono-rt]    --- End of inner exception stack trace ---
      [mono-rt]   at Example.Services.RealmService.GetInstanceAsync (System.String partitionKey) [0x0017a] in D:\TextflowMobile\Example\Services\RealmService.cs:80 
      [mono-rt]   at Example.Services.UpdaterService.StartUpdater (System.Boolean quickStart) [0x00057] in D:\TextflowMobile\Example\Services\UpdaterService.cs:149 
      [mono-rt]   at Example.ViewModels.LoginViewModel.<get_LoginCommand>b__21_0 () [0x00106] in D:\TextflowMobile\Example\ViewModels\LoginViewModel.cs:87 
      [mono-rt]   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.28(intptr,intptr)
      [mono-rt]   at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.28(intptr,intptr)
      

      Relevant log output

      No response

            Assignee:
            andrea.catalini@mongodb.com Andrea Catalini (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: