Use ObjectID in Realm database on a UWP project (xamarin.forms)

When using ObjectID in xamarin.forms with UWP and native compiling an error occures. I get the exception:

System.Runtime.InteropServices.MarshalDirectiveException: Incompatible MarshalAs detected in parameter named 'value'. Please refer to MCG's warning message for more information.
   at __Interop.realm_wrappers.get_primitive__0(ObjectHandle, IntPtr, PrimitiveValue&, NativeException&) + 0x63
   at Realms.ObjectHandle.NativeMethods.get_primitive(ObjectHandle, IntPtr, PrimitiveValue&, NativeException&) + 0x8
   at Realms.ObjectHandle.GetPrimitive(IntPtr, PropertyType) + 0x3b
   at Realms.RealmObjectBase.GetRealmIntegerValue[T](String) + 0x33
   at TrackTime.Helpers.DateTimeHelper.SetCulture(PersonRealmObject) + 0x293
   at TrackTime.App.OnStart() + 0x481

It seams that using ObjectID is not suported on .NET xamarin.forms for UWP!

Which version of the .NET SDK are you using?

I’m using the .NET 10.0.0 beta-2

Based on the stacktrace, this doesn’t appear to be related to ObjectId. Instead, it’s likely caused by the same issue that causes https://github.com/realm/realm-dotnet/issues/1780.

Unfortunately it seems to be. I was spending around 40 hrs tracking the problems in a close to release app with realm and Xamarin.forms. One of the problems was with the IList. It can be very easy solved by adding a wrapper RealmObject around the string within the list - works perfect. But I used also the new ObjectID which was not working. I did extensive tests with a test program and different scenarios. As soon as I changed the ObjectID to string the test program was working like a charm. If you like I can send the small visual studio 2019 test-project containing the different situations.

With the app facing the problem I had to go back to the realm.database 5.1.2 and reverse the change from ObjectID to string and GUID where as the problem doesn’t exist. The app is now running with native compilation perfect without any exception.

I’d love to take a look at the ObjectId issues. If you have a repro please open an issue in the .NET repo: https://github.com/realm/realm-dotnet/issues.

1 Like