Search Unity

MissingMethodException for default constructors in DLLs

Discussion in 'WebGL' started by sharkyx, Dec 6, 2015.

  1. sharkyx

    sharkyx

    Joined:
    Mar 20, 2013
    Posts:
    8
    WebGL builds don't seem to work when a class is only instantiated through Activator.CreateInstance and the class is in a DLL assembly.

    In these circumstances, trying to instantiate the class with CreateInstance results in
    Code (csharp):
    1. System.MissingMethodException: Method not found: 'Default constructor not found...ctor() of InsertClassNameHere'
    The case number is 741756
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,633
    This is due to il2cpp's dll stripping. If a class is instantiated through CreateInstance, it's constructor is only ever referenced by reflection, which the linker cannot detect, and thus the constructor will be stripped. The solution is to provide a link.xml file, telling the stripper not to strip that constructor.

    See this documentation page for more information:
    http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html
     
    Playcorp, _creatio_ and Anisoropos like this.
  3. sharkyx

    sharkyx

    Joined:
    Mar 20, 2013
    Posts:
    8
    I'll have a look, thanks!
     
unityunity