Search Unity

IL2CPP issue: Sgen.exe with xsi:type = Inherited types cannot be parsed by XmlSerializer

Discussion in 'General Discussion' started by michaellabster, Apr 2, 2021.

  1. michaellabster

    michaellabster

    Joined:
    Dec 10, 2015
    Posts:
    1
    I have built a very simple test project below, to illustrate a bug I'm running into when using IL2CPP and xsi:type with sgen.exe pre-compiled Xml Serializer.
    Any ideas/suggestions on how to fix this would be greatly appreciated.

    I have this very simple XML:
    Code (CSharp):
    1. <Engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    2.     <Child xsi:type="MyType" />
    3. </Engine>
    Which follows this simple class structure:
    Code (CSharp):
    1. [Serializable]
    2. public class Engine
    3. {
    4.     public BaseType Child;
    5. }
    6.  
    7. public class BaseType { }
    8. public class MyType : BaseType { }
    To speed up loading, we use sgen.exe, to generate the pre-compiled XmlSerializer.dll and place it in the project Plugins folder.
    The following command then calls the pre-compiled XmlSerializer to create the Engine object:
    Code (CSharp):
    1. new Microsoft.Xml.Serialization.GeneratedAssembly.EngineSerializer().Deserialize(xml);
    I can then use the XML above, with xsi:type to load the inherited "MyType".
    And this all works fine in Mono! But as soon as I switch to IL2CPP (using .NET 4.0) I get the following error.
    It seems like the IL2CPP stripping process is somehow removing the type, but I've even tried using
    link.xml
    to force include the full XmlSerializer.dll.

    Code (CSharp):
    1. InvalidOperationException: The specified type was not recognized: name='MyType' namespace='', at <Child xmlns=''>
    2.   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_BaseType (System.Boolean isNullable, System.Boolean checkType) [0x00000] in <00000000000000000000000000000000>:0
    3.   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_Engine (System.Boolean isNullable, System.Boolean checkType) [0x00000] in <00000000000000000000000000000000>:0
    4.   at Microsoft.Xml.Serialization.GeneratedAssembly.EngineSerializer.Deserialize (System.Xml.Serialization.XmlSerializationReader reader) [0x00000] in <00000000000000000000000000000000>:0
    5.   at System.Xml.Serialization.XmlSerializer.Deserialize (System.IO.Stream stream) [0x00000] in <00000000000000000000000000000000>:0
    6.   at SerializerTest.Start () [0x00000] in <00000000000000000000000000000000>:0
    7.  
    8. (Filename: currently not available on il2cpp Line: -1)

    Any ideas/suggestions on how to fix this?
    I've attached the small sample project as well.
     

    Attached Files: