WebGL project exception when deployed

[Not sure where to put this thread, hopefully if there is an appropriate forum I didn’t see a moderator will move it!]

I have an Unity project which I’ve successfully deployed to PC and tablet as a desktop app. The project communicates with a WCF webservice on one of our servers while it’s running. I’m now trying to get it to deploy in WebGL, and it’s failing to connect to the webservice and generating the following error:

“NotSupportedException: C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Reflection.Emit\AssemblyBuilder.cpp(22) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.”

I’m not using System.Reflection.Emit anywhere in the project that I can tell. I’ve had a Google, and I can find only a few similar problems, and they’re resolved by disabling 3rd party plugins, which I don’t believe I’m using.

Any help much appreciated! :slight_smile:

I’m using System.ServiceModel.ClientBase.Channel to callback to the server. I suspect this is the problem, but I’m not sure what to do about it!

In order to track down how the code is getting into System.Reflection.Emit, you can enable full stack trace support on WebGL. Enable the “Development build” option in the Build Settings and set “Enable Exceptions” to a value of “Full” in the WebGL Player Settings. That should give you a better managed call stack when this error occurs (it will be in the browser’s console window).

You’ll need to remove/not call the code which calls into System.Reflection.Emit, as runtime code generation is not supported on WebGL.

This is the exception text (anonymised.) So basically it looks like I can’t use the WCF stuff, even though I’m not touching the System.Net namespace. This is deeply annoying, and looks like I basically have to re-write everything.

blob:http://{LOCALURL}/bb330cd5-bd80-4990-97f4-2c548e3b91ad:8863 NotSupportedException: C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Reflection.Emit\AssemblyBuilder.cpp(22) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.
System.Reflection.Emit.AssemblyBuilder.basic_init (System.Reflection.Emit.AssemblyBuilder ab)
System.Reflection.Emit.AssemblyBuilder…ctor (System.Reflection.AssemblyName n, System.String directory, AssemblyBuilderAccess access, Boolean corlib_internal)
System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, AssemblyBuilderAccess access, System.String dir, System.Security.Policy.Evidence evidence, System.Security.PermissionSet requiredPermissions, System.Security.PermissionSet optionalPermissions, System.Security.PermissionSet refusedPermissions, Boolean isSynchronized)
System.AppDomain.DefineDynamicAssembly (System.Reflection.AssemblyName name, AssemblyBuilderAccess access)
Mono.CodeGeneration.CodeModule…ctor (System.String name)
System.ServiceModel.ClientProxyGenerator.CreateProxyType (System.Type contractInterface, System.ServiceModel.Description.ContractDescription cd, Boolean duplex)
System.ServiceModel.ChannelFactory1[System.Object].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) System.ServiceModel.ChannelFactory1[System.Object].CreateChannel (System.ServiceModel.EndpointAddress address)
System.ServiceModel.ChannelFactory1[System.Object].CreateChannel () System.ServiceModel.ClientBase1[System.Object].CreateChannel ()
System.ServiceModel.ClientBase1[System.Object].get_InnerChannel () System.ServiceModel.ClientBase1[System.Object].Close ()
System.ServiceModel.ClientBase`1[System.Object].System.IDisposable.Dispose ()
ServerComms.CheckServer (System.String& errorMessage)
SceneOperations_LoginScene+c__Iterator22.MoveNext ()
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress)
UnityEngine.MonoBehaviour.StartCoroutine_Auto (IEnumerator routine)
UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine)
SceneOperations_LoginScene.Start ()
UnityEngine.Debug:LogException(Exception)
ServerComms:CheckServer(String&)
c__Iterator22:MoveNext()
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
SceneOperations_LoginScene:Start()

Unfortunately there is not much we can do. Maybe WCF has a AOT-friendly code path that does not use System.Reflection.Emit, but a quick search did not turn up anything for me. The WebGL, iOS, and console platforms for Unity are all restricted to AOT, so this won’t work in any of those cases.