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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Reflection.Emit not supported, because this lines of code?

Discussion in 'WebGL' started by Guirao, Sep 4, 2017.

  1. Guirao

    Guirao

    Joined:
    Nov 24, 2012
    Posts:
    68
    I have built a webGL build of my prototype and I came up with and IL2CPP emit generate dyanmic method not supported.

    Is it because of any of these lines of code? It's the only reflection i use.

    Code (CSharp):
    1.  
    2. Type c = typeof( ItemGenerator );
    3. MethodInfo method = c.GetMethod( "GenerateEquipment" , BindingFlags.Static | BindingFlags.Public );
    4. MethodInfo genericMethod = method.MakeGenericMethod( new[ ] { saveEquip.itemType } );
    5. var result = genericMethod.Invoke( null , new object[ ] { saveEquip.seed , saveEquip.level , saveEquip.rarity , saveEquip.refineLevel } );
    6.  
    Code (CSharp):
    1.  T item = ( T ) Activator.CreateInstance( typeof( T ) );
    If it's not this, can it be because I'm using newtonsoft json plugin?
     
    Last edited: Sep 4, 2017
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Reflection.Emit is not supported on il2cpp platforms.
     
  3. Guirao

    Guirao

    Joined:
    Nov 24, 2012
    Posts:
    68
    I know, I only asked if I was using any Emit feature on these lines of code.

    It works fine on ios using IL2CPP...
     
  4. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    Are you using the .NET 4.6 profile by any chance? I know it compiles to IL2CPP, but there are some instances e.g. XmlSerializer that uses System.Reflection.Emit in the .NET 4.6 profile as opposed to the .NET 3.5 one before passing through Emscripten.
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    If you're using the official release of Newtonsoft.Json and not something like my port on the asset store, then yes this will be your problem. By default it makes extensive use of Reflection.Emit and is not AOT (or IL2CPP) friendly. That's the reason the port exists. :)