Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VergilUa opened this issue Dec 2, 2022 · 5 comments
Labels

Comments

@VergilUa
Copy link

VergilUa commented Dec 2, 2022

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.

@salarcode
Copy link
Owner

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

@salarcode salarcode added the bug label Dec 2, 2022
@salarcode
Copy link
Owner

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

@VergilUa
Copy link
Author

VergilUa commented Dec 2, 2022

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.

@salarcode
Copy link
Owner

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

@VergilUa
Copy link
Author

VergilUa commented Dec 2, 2022

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 VergilUa changed the title Dynamic method emit prevents usage on some platforms (alike Android) Dynamic method emit prevents usage on some platforms (Unity + Android / IOS) Dec 2, 2022
@VergilUa VergilUa changed the title Dynamic method emit prevents usage on some platforms (Unity + Android / IOS) Dynamic method emit prevents usage on some platforms (Unity IL2CPP + Android / IOS) Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants