NotSupportedException (With log detail)

I attempted to run my game on iOS and got the following crash. Any ideas what the problem could be or how I can try fixing the issue?
Unity version: Unity 2018.2.1
Log Text:
2018-08-03 05:56:01.392329-0500 justflip[548:112091] Built from ‘2018.2/release’ branch, Version ‘2018.2.1f1 (1a9968d9f99c)’, Build type ‘Release’, Scripting Backend ‘il2cpp’
2018-08-03 05:56:01.394698-0500 justflip[548:112091] → registered mono modules 0x1062014d0
→ applicationDidFinishLaunching()
→ applicationDidBecomeActive()
GfxDevice: creating device client; threaded=1
Initializing Metal device caps: Apple A11 GPU
Initialize engine version: 2018.2.1f1 (1a9968d9f99c)
Save game data
PersistanceManager:Initialize()
LoadGameState:Enter()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

Serialize game state
PersistanceManager:SaveGameData()
LoadGameState:Enter()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

NotSupportedException: /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.
at System.Reflection.Emit.AssemblyBuilder…ctor (System.Reflection.AssemblyName n, System.String directory, System.Reflection.Emit.AssemblyBuilderAccess access, System.Boolean corlib_internal) [0x00000] in <00000000000000000000000000000000>:0
at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, System.String dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, System.Boolean isSynchronized) [0x00000] in <00000000000000000000000000000000>:0
at System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in <00000000000000000000000000000000>:0
at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly (System.Xml.Serialization.XmlMapping[ ] xmlMappings, System.Type[ ] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence) [0x00000] in <00000000000000000000000000000000>:0
at System.Xml.Serialization.TempAssembly…ctor (System.Xml.Serialization.XmlMapping[ ] xmlMappings, System.Type[ ] types, System.String defaultNamespace, System.String location, System.Security.Policy.Evidence evidence) [0x00000] in <00000000000000000000000000000000>:0
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly (System.Xml.Serialization.XmlMapping xmlMapping, System.Type type, System.String defaultNamespace) [0x00000] in <00000000000000000000000000000000>:0
at System.Xml.Serialization.XmlSerializer…ctor (System.Type type, System.String defaultNamespace) [0x00000] in <00000000000000000000000000000000>:0
at PersistanceManager.SaveGameData () [0x00000] in <00000000000000000000000000000000>:0
at LoadGameState.Enter () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)

(Filename: currently not available on il2cpp Line: -1)

justflip was compiled with optimization - stepping may behave oddly; variables may not be available.

Well I think I found the issue.

The XML Serializer I’m using utilizes System.Reflection.Emit which is not supported under iOS:

Please try using the .NET Standard 2.0 Api Compatibity Level option. That .NET class library implementation should allow the XMLSerializer class to work correctly with the AOT restrictions on iOS. Starting in Unity 2018.3, either Api Compatibility Level option can be used.

2 Likes

I’ve been using XMLSerializer on iOS for many years without any issues.

This is a bug specific to the .NET 4.x Equivalent scripting runtime. XmlSerializer in general does work fine on iOS.

This also applies to Android (Unity 2018.2.17f building for Android 7.1)
Scripting Runtime 4.x; IL2CPP; API Compat 4.x

I added XMLSerializer and started getting a similar stacktrace via logcat.
The funny part is that this does not occur, when building a “Development Build” Player with Script Debugging enabled.
When building a non-development player, I receive a NotSupportedException regarding System.Reflection.Emit

That is rather odd, I don’t think that script debugging should have an impact on this behavior.

Pretty same thing happened to me working with System.ServiceModel.dll. I documented my issue on StackOverflow.

Now, half a year later - this kind of major bug is known since half a year now - it’s still present in Unity 2018.2.20. This really gives me the kicks! Everything works fine in the editor, and when you try to build the WebGL build, you get grounded hard. annoying as hell.

Note that this should be corrected in Unity 2018.3. In Unity 2018.2 you will need to use the .NET Standard 2.0 Api Compatibility level to work around the problem.

Are you seeing this issue with .NET Standard 2.0 in Unity 2018.2?

Thank you! Setting back to .NET 2.0 Api fixed it for our release. Now looking forward to test it in 2018.3.

@JoshPeterson I was experiencing a similar issue at runtime since updating from .NET 3.5 to 4.x:
NotSupportedException: /Users/builduser/buildslave/unity/build/External/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/AssemblyBuilder.cpp(20) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.

We might not be ready for a 2018.3 upgrade just yet (it’s a very large project), so I switched the API Compatibility to Standard 2.0 per your suggestion…and now I get an error at buildtime instead:
14035: [Unity] IL2CPP error for method 'System.Void Boo.Lang.Runtime.DynamicDispatching.Emitters.DispatcherEmitter::.ctor(System.Type,System.String)' in assembly '/BUILD_PATH/[projectname]/Temp/StagingArea/Data/Managed/Boo.Lang.dll'
14036: [Unity] il2cpp.exe didn't catch exception: System.InvalidOperationException: attempting to call method 'System.Void System.Reflection.Emit.DynamicMethod::.ctor(System.String,System.Type,System.Type[ ],System.Type)' that does not exist

Any suggestions? :slight_smile:

The first error (the one as runtime) indicates that IL2CPP does not support System.Reflection.Emit, which is expected. IL2CPP is an ahead-of-time (AOT) runtime, so it cannot emit dynamic code.

The second error is a bit odd - I don’t think that IL2CPP should error in this case.

However the deeper issue is that the code in this project is trying to use System.Reflection.Emit with IL2CPP, which is not support (no matter what the Api Compatibility Level is). Can you determine what code in the project is trying to emit dynamic code?

Searching the codebase itself, the only explicit references to System.Reflection.Emit are within platform-specific #if conditions that exclude UNITY_IOS. However, I do have a third-party plugin using System.Xml.Serialization’s XmlSerializer - and the moment when it initializes is approximately the moment that the runtime error occurs.

Do you know if the third-party code is using XmlSerializer from the class libraries that Unity ships or from another implementation? The ones that Unity ships should be safe for AOT platforms. If there is some other assembly or implementation being used, that may not be the case.

We’re also getting a similar issue after moving to .Net 4.6 (Experimental) & IL2CPP in 2017.4.16, and it’s also stemming from the in-built xml serialiser (wth a var serializer = new XmlSerializer call). The move was due to 64bit build requirements.

Is it possible for you to try a newer version of Unity, maybe in the 2018.4 series? I wonder if this issue has been corrected in a newer version.

We have also the same issue, using Unity 2019.2.0f1

1 Like

Can you provide specific details about the error message you see in this case?

Also getting the Error. Using Unity 2019.2.0f1. The newest version of the JSON .NET Port in the Assets Store. Compatibility set to .NET 4.X.
Produces this error on build:
Convert of JSON failed: System.Reflection.Emit.DynamicMethod::.ctor