Dynamic type in Xamarin.iOS with Realm

Asked by At

I have an API in which the value of a key can come as int, string or dictionary.

I was using object keyword as the type for the value and it worked fine.

But once I implemented Realm compiler gave me an error.

Error: Fody/RealmWeaver: MyClass.Value is a 'System.Object' which is not yet supported.

Ok fine so object is not supported by Realm. Then I tried using dynamic keyword as the type. I got the following error.

Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' (CS0656)

Googling this led me to this comment which says dynamic keyword is not allowed on iOS because JIT compilation is not allowed.

So what to do in this situation?

1 Answers

0
Simon On

The Realm weaver only supports a subset of known types

  • String
  • ByteArray
  • Char
  • Byte
  • Int16
  • Int32
  • Int64
  • Single
  • Double
  • Boolean
  • DateTimeOffset
  • And the nullable variants of the above

as defined here https://github.com/realm/realm-dotnet/blob/master/Weaver/RealmWeaver.Fody/ModuleWeaver.cs#L34

So you are falling through to this exception https://github.com/realm/realm-dotnet/blob/master/Weaver/RealmWeaver.Fody/ModuleWeaver.cs#L481

So you need to change MyClass.Value to one of the known types