Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Reflection support missing with WebGL build

Discussion in 'WebGL' started by iileychen, Aug 24, 2016.

  1. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    96
    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?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,741
    @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.
     
  3. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    96
    Thank you Josh for the explain, that is great WebGL works with reflection.
    Yes, i am using 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?
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,741
    @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/...protobuf-net-getting-executionengineexception).

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

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    96
    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.