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

System.InvalidCastException: Unable to cast object of type 'EventLoop' to type 'ShouldCompactDelegate'.

      <!--- Questions: If you have questions about how to use Realm, please ask on -->
      <!--- StackOverflow: http://stackoverflow.com/questions/ask?tags=realm -->
      <!--- We monitor the realm tag. -->

      <!--- Feature Request: Just fill in the first two sections below. -->

      <!--- Bugs: To help you as fast as possible with an issue please describe your issue -->
      <!--- and the steps you have taken to reproduce it in as much detail as possible. -->

      <Unable to render embedded object: File (--- Thanks for helping us help you) not found. -->

      Our project is Xamarin Universal Windows Platform (UWP)
      Running Realm 4.3.0 (from NuGet package)
      If a migration is required, it seems realm config will either run the migration callback or a compact on launch, but we are getting an error when we try both in the same config.

      We are only running Realm instances in the clients, not syncing to a server (yet). Our Xamarin project is running UWP, Android and iOS versions. UWP is the only one showing this issue.

      Goals

      We need to be able to run both a migration and a compact if a migration is required.
      <!--- What are you trying to achieve? -->

      Expected Results

      We expect to run both without exception, both compacting the db if needed and running the migration callback when migration is needed.
      <!--- What did you expect to happen? -->

      Actual Results

      Getting the following error:

      System.InvalidCastException: Unable to cast object of type 'EventLoop' to type 'ShouldCompactDelegate'.
      	at Realms.RealmConfiguration.ShouldCompactOnLaunchCallback(IntPtr delegatePtr, UInt64 totalSize, UInt64 dataSize)
      	at Realms.SharedRealmHandle.NativeMethods.open(Configuration configuration, SchemaObject[] objects, Int32 objects_length, SchemaProperty[] properties, Byte[] encryptionKey, NativeException& ex)
      	at Realms.SharedRealmHandle.Open(Configuration configuration, RealmSchema schema, Byte[] encryptionKey)
      	at Realms.RealmConfiguration.CreateRealm(RealmSchema schema)at ERPXamarin.Models.AppModel.CompactRealm()
      

      <!--- What happened instead? -->
      <!--- e.g. the stack trace of a crash -->

      Steps to Reproduce

      The code sample below will catch an error if a migration is required.

      I'm testing the migration by removing our application from the client, reverting back to an earlier version of our project which had Realm 4.2.0, running and installing, then upgrading to the latest version of our project which has Realm 4.3.0. The SchemaVersion is increased by 12.

      If I remove ShouldCompactOnLaunch then MigrationCallback is called and the migration is successful. If I remove MigrationCallback, then ShouldCompactOnLaunch is called and does not result in an error. If both are included (if a migration is required) then ShouldCompactOnLaunch callback is run and then the error pops after that and MigrationCallback is never called.

      <!--- What are steps we can follow to reproduce this issue? -->

      Code Sample

      var config = new RealmConfiguration(RealmConfiguration.DefaultRealmName)
      {
      	SchemaVersion = 20,
      	MigrationCallback = (Migration migration, ulong oldVersion) =>
      	{
      		//Do stuff here
      	},
      	ShouldCompactOnLaunch = (ulong totalBytes, ulong bytesUsed) =>
      	{
      		return bytesUsed/totalBytes < 0.9;
      	}
      };
      
      try
      {
      	var realm = Realm.GetInstance(config);
      	realm.Dispose();
      }
      catch (Exception e)
      {
      	//Error here: System.InvalidCastException
      }
      

      <!--- Please provide a code sample or test case that highlights the issue. -->
      <!--- If relevant, include your model definitions. -->
      <!--- For larger code samples, links to external gists/repositories are preferred. -->
      <!--- Alternatively, you can share information confidentially via email at help@realm.io. -->
      <Unable to render embedded object: File (--- Full projects that we can compile and run ourselves are ideal) not found. -->

      Version of Realm and Tooling

      • Realm Object Server Version:
      • Flavor:
        • [ ] Realm Cloud
        • [x] Self-Hosted
      • Server OS & Version: Only using Realm locally
      • Client SDK Version: 4.3.0
      • Client OS & Version: Windows 10, version 1903

            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: