[RESOLVED] System.Reflection.Emit problem on WebGL build [B14]

I have build the project for WebGL and found this happy error message in runtime:

Error message

[Error] NotSupportedException: Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/AssemblyBuilder.cpp(22) : Unsupported internal call for IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.

_JS_Log_Dump (SV-dev.js, line 10084)
_JS_Log_Dump__wrapper (SV-dev.js, line 6151924)
dynCall_vii (SV-dev.js, line 6147376)
invoke_vii (SV-dev.js, line 16097)
__Z40DebugStringToFilePostprocessedStacktracePKcS0_S0_iS0_iiiiPFvRK11CppLogEntryE (SV-dev.js, line 2246298)
dynCall_viiiiiiiiii (SV-dev.js, line 6056041)
invoke_viiiiiiiiii (SV-dev.js, line 16193)
__ZN9Scripting12LogExceptionEP18ScriptingExceptioniRKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE (SV-dev.js, line 3818511)
dynCall_viii (SV-dev.js, line 6141833)
invoke_viii (SV-dev.js, line 14993)
__ZN25ScriptingInvocationNoArgs6InvokeEPP18ScriptingException (SV-dev.js, line 4218115)
__ZN25ScriptingInvocationNoArgs6InvokeEv (SV-dev.js, line 6064428)
__ZN13MonoBehaviour16CallUpdateMethodEi (SV-dev.js, line 4032119)
__ZN13MonoBehaviour6UpdateEv (SV-dev.js, line 6140252)
__ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv (SV-dev.js, line 3448142)
__ZN16BehaviourManager6UpdateEv (SV-dev.js, line 6131679)
dynCall_vi (SV-dev.js, line 6152013)
invoke_vi (SV-dev.js, line 16273)
__Z10PlayerLoopbbP10IHookEvent (SV-dev.js, line 448988)
__ZL8mainloopv (SV-dev.js, line 5678428)
dynCall_v (SV-dev.js, line 6154843)
dynCall (SV-dev.js, line 203)
(anonymous function) (SV-dev.js, line 10207)
runIter (SV-dev.js, line 6961)
Browser_mainLoop_runner (SV-dev.js, line 10203)

Well, first of all, this message is not very informative. I can’t find any ‘using System.Reflection.Emit’ in our code, so probably it’s somewhere in dll files. Probably it’s possible to improve those error messages to help out a little bit?

Update. Our game runs perfectly on iOS, so we don’t use Reflection. Therefore, if anything still is using reflection, it’s because of a compiler flag that needs to be edited to include UNITY_WEBGL just like UNITY_IPHONE. So wee need to figure out where and what is doing it.

Could you give us a list of the third party assets you’re using? We might be able to help you narrow it down. For instance, if you’re using my JSON .NET for Unity asset, it does not yet have flags for WebGL.

(I’m working on the same project as the original poster)

We also have some various other advertising and tracking native code plugins that should only run on mobile, and they tend to use their own json plugin also. But, those should only be running on mobile, not on web or webGL builds.

  • CBJSON.cs (chartboost)
  • MiniJSON.cs (amazon mobile game sdk, facebook, does run on web builds)
  • SimpleJSON.cs (facebook, does run on web builds)

It really could be anything. I’m hoping there is a way we can get more debugging info so we can get some hint about what C# code it is running when the exception happens.

The DLL files that might be causing the reflection error:

  • HOTween.dll (tweening plugin)

  • P31RestKit.dll (prime 31, but we only use native code plugins so none of them should actually be doing anything on web builds)

  • Newtonsoft.Json.dll (not sure what is using this, it’s in a WP8 folder so I’m assuming it’s only for windows phone builds)

  • JMOAssets.dll (particle fx plugin)

  • TMPro_Plugin.dll (text mesh pro)

  • ICSharpCode.SharpZipLib.dll (zip file support)

  • IFacebook.dll (official facebook plugin)

You’re right that Newtonsoft will only run for WP8 otherwise I’d say that’s the culprit. My guess would be either miniJson or JsonFX.

I should also note that WebGL is still in Beta and there are Reflection bits that don’t work. You actually are using Reflection on iOS, just not Reflection.Emit. My Newtonsoft port makes a lot of changes for iOS and Android to be able to construct objects without using Reflection.Emit but rather simply invoking the default constructor.

I’ve been working on WebGL support but it has been slow going. I cannot get a WebGL Build to work in Beta 14 or 15. I can build fine in Beta 13 but deserialization doesn’t work as it throws an exception (which isn’t very descriptive) when trying to construct an object. WebGL support will be spotty for awhile because it’s still very much in beta and will be hard for publishers to support just yet.

1 Like

I’ve narrowed it down a bit further but it’s very hard to debug WebGL unless I’m missing something. Actually constructing the objects works fine. However there is some LINQ stuff that’s breaking. Even using GetFields on a type works fine, but trying to add them to a generic list using AddRange appears to be blowing up.

Thank you for trying to help us with our problem.
But I think I found the root of problem. HOTween was causing this error. After I changed regular HOTween plugin to HOTweenMicro I have never faced that Emit error again.

4 Likes