# Reflection support missing with WebGL build

**URL:** https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536
**Category:** Web
**Created:** [August 24, 2016, 11:02am UTC](https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536 "2016-08-24T11:02:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iileychen](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/iileychen/32/102275_2.png) [@iileychen](https://discussions.unity.com/u/iileychen)
#### Post date: [August 24, 2016, 11:02am UTC](https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536/1 "2016-08-24T11:02:24Z")

</div>

I can build my project to webgl well, but at runtime it throws the error:

> [@](#):
>
> System.InvalidOperationException: It was not possible to prepare a serializer for: common.InitInfo —\> System.NotSupportedException: /Applications/Unity/Unity.app/Contents/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(21) : Unsupported internal call for IL2CPP/DynamicMethod::create\_dynamic\_method - System.Reflection.Emit is not supported.

But it runs well in standalone version. So, does that mean the whole Reflection thing will not work in webgl export?

---

<div class="post-metadata">

### Author: ![JoshPeterson](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joshpeterson/32/44179_2.png) [@JoshPeterson](https://discussions.unity.com/u/JoshPeterson)
#### Post date: [August 24, 2016, 11:21am UTC](https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536/2 "2016-08-24T11:21:04Z")

</div>

> [@iileychen](#):
>
> I can build my project to webgl well, but at runtime it throws the error:
> 
> But it runs well in standalone version. So, does that mean the whole Reflection thing will not work in webgl export?

@iileychen

While reflection will work (i.e. the System.Reflection namespace), dynamic code generation via reflection (i.e. the System.Reflection.Emit namespace) will not work. WebGL is an ahead-of-time (AOT) compiled platform, like iOS and many consoles (XBox One, PS4, etc.). It does not support generation of code at runtime.

This can be a problem for many serializers, as might be the case here. However, some of them do have an AOT mode which works with WebGL.

---

<div class="post-metadata">

### Author: ![iileychen](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/iileychen/32/102275_2.png) [@iileychen](https://discussions.unity.com/u/iileychen)
#### Post date: [August 24, 2016, 3:53pm UTC](https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536/3 "2016-08-24T15:53:14Z")

</div>

Thank you Josh for the explain, that is great WebGL works with reflection.  
Yes, i am using [protobuf-net](https://github.com/mgravell/protobuf-net) , seems it is the best solution for Unity, but i failed to run it with webgl with that error.

Do you know is there a way to make (protocol buffers) works in WebGL?

---

<div class="post-metadata">

### Author: ![JoshPeterson](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joshpeterson/32/44179_2.png) [@JoshPeterson](https://discussions.unity.com/u/JoshPeterson)
#### Post date: [August 24, 2016, 4:05pm UTC](https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536/4 "2016-08-24T16:05:24Z")

</div>

> [@iileychen](#):
>
> Thank you Josh for the explain, that is great WebGL works with reflection.  
> Yes, i am using [protobuf-net](https://github.com/mgravell/protobuf-net) , seems it is the best solution for Unity, but i failed to run it with webgl with that error.
> 
> Do you know is there a way to make (protocol buffers) works in WebGL?

@iileychen

I’m not aware of a way to do this myself, but a Google search for “protobuf-net aot” indicates that it might be possible (there is some discussion here: [http://stackoverflow.com/questions/5098459/c-sharp-mono-aot-with-protobuf-net-getting-executionengineexception](http://stackoverflow.com/questions/5098459/c-sharp-mono-aot-with-protobuf-net-getting-executionengineexception)).

If you can get protobuf-net work work with AOT, then it should work on WebGL.

---

<div class="post-metadata">

### Author: ![iileychen](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/iileychen/32/102275_2.png) [@iileychen](https://discussions.unity.com/u/iileychen)
#### Post date: [August 25, 2016, 6:00pm UTC](https://discussions.unity.com/t/reflection-support-missing-with-webgl-build/637536/5 "2016-08-25T18:00:34Z")

</div>

Thank you Josh, your information really helps, finally i found some way to use protobuf-net with aot : precompile the serialization classes, and include the compiled DLL to the project… that is too complex so i give up the whole thing about proto buffer or FlatBuffer i used before, the seems make things complex since i don’t serialization cross language now.

What i need is just a simple fast C# object serialization and very luck of WebGL support basic Reflection, so i write a simple one by myself. That is good for it, most classes in System.Reflection package really works.
