How to load an assetbundle with scripts in webGL

So I’m working on a project that uses Unity WebGL to display different machines/parts/… in 3D, these parts or machines are selected by the user and then loaded into a scene (for now the scene stays the same).

Because of the large amount of choices we want to create different asset bundles, containing 1 or more parts each, so we can download these on-demand.

I’ve done this successfully by passing the URL to LoadFromCacheOrDownload and extracting the gameObject from the www object.

Now we would also like to include scripts with the assets to create animations and user interaction. I followed the explanation given here: http://docs.unity3d.com/Manual/scriptsinassetbundles.html, and this works perfectly in the WebPlayer. In webGL however, which is the requirement for our project, it gives the following error:

NotSupportedException: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System/AppDomain.cpp(184) : Unsupported internal call for IL2CPP:AppDomain::LoadAssemblyRaw - "This icall is not supported by il2cpp."
System.AppDomain.LoadAssemblyRaw (System.Byte[] rawAssembly, System.Byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence, Boolean refonly)
System.AppDomain.Load (System.Byte[] rawAssembly, System.Byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence, Boolean refonly)
System.AppDomain.Load (System.Byte[] rawAssembly, System.Byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence)
System.AppDomain.Load (System.Byte[] rawAssembly)
System.Reflection.Assembly.Load (System.Byte[] rawAssembly)
API+c__Iterator0.MoveNext ()

It seems to stem from the call “System.Reflection.Assembly.Load(txt.bytes);” (as seen in the example), so I suppose the Reflection class is not (yet?) fully supported for WebGL.

So my question is - is there a way around using Reflection for this? At best I’m hoping for some different code that can fix this, at worst that we will have to create the scripts for WebGL in Javascript and add them as such instead of as a binary? I’m a bit lost here so any leads are appreciated.

Thanks in advance

As Josh Petersen answered on Stack Overflow:

No, there is no way around this restriction with reflection.

The key difference between the web player and WebGL build targets in Unity in this case is that WebGL uses AOT (ahead-of-time) compilation, whereas the web player uses JIT (just-in-time) compilation. With AOT compilation, it is not possible to load an assembly at run-time that was not present at compile time.

Of course, it is possible to load JavaScript code at runtime, so as you suggest, you’ll probably need to go this route.