Bois icon indicating copy to clipboard operation
Bois copied to clipboard

Dynamic method emit prevents usage on some platforms (Unity IL2CPP + Android / IOS)

Open VergilUa opened this issue 3 years ago • 5 comments

Calling into reflection emit will cause a PlatformNotSupportedException. (which is called into upon initialization)

PlatformNotSupportedException: Operation is not supported on this platform. at System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Reflection.Module m, System.Boolean skipVisibility) [0x00000] in <00000000000000000000000000000000>:0 at Salar.Bois.Types.BoisTypeCompiler.ComputeWriter (System.Type type, Salar.Bois.Types.BoisComplexTypeInfo typeInfo, System.Action1[T] beforeMehodBody, System.Reflection.Module containerModule) [0x00000] in <00000000000000000000000000000000>:0 at Salar.Bois.Types.BoisTypeCache.GetRootTypeComputed (System.Type type, System.Boolean generateReader, System.Boolean generateWriter) [0x00000] in <00000000000000000000000000000000>:0

Possible solution to this is to perform Ahead-Of-Time compilation of the methods & types required.

VergilUa avatar Dec 02 '22 09:12 VergilUa

Thanks for letting me know, this needs some investigation and possibility I need to fall back to reflection on unsupported platforms

salarcode avatar Dec 02 '22 10:12 salarcode

Can you give me your device details please? And are you using MAUI or Xamarin?

salarcode avatar Dec 02 '22 10:12 salarcode

This affect all devices basically, since its a platform restriction. Similar will happen with IOS.

For the testing purposes I've used Unity + .Net 2.1.

Reflection "reading" is fine, generating new code is not.

VergilUa avatar Dec 02 '22 10:12 VergilUa

I believe it is Unity problem then MAUI has support for Emits

salarcode avatar Dec 02 '22 10:12 salarcode

I think its more of an IL2CPP issue (no emit support), because it expects everything to be compiled AOT. Still, would be great to have an AOT variant for the lib. Similar to what other serializers do;

https://forum.unity.com/threads/notsupportedexception-with-log-detail.543644/#post-8186325

VergilUa avatar Dec 02 '22 11:12 VergilUa