Search Unity

DLL problems with compiled protobuf-net type model

Discussion in 'Scripting' started by GroundCombo, Aug 16, 2019.

  1. GroundCombo

    GroundCombo

    Joined:
    Jan 23, 2015
    Posts:
    29
    Our game uses protobuf-net (2.4.0 DLL out of the nuget package) for save serialization, but it is not compatible with IL2CPP due to runtime trickery. To fix that, I made an editor tool to use protobuf-net's built-in compilation feature that makes a DLL out of precompiled type serializers. The DLL itself works fine in a build, but it results in seemingly random built-in types getting broken in the editor:

    Code (CSharp):
    1.  
    2. TypeLoadException: Could not load type UnityEngine.UI.Dropdown, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null while decoding custom attribute: (null)
    3. System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0)
    4. System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0)
    5. System.RuntimeType.GetCustomAttributes (System.Boolean inherit) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0)
    6. UnityEngine.AttributeHelperEngine.GetExecuteMode (System.Type klass) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AttributeHelperEngine.cs:122)
    7. UnityEngine.AttributeHelperEngine.CheckIsEditorScript (System.Type klass) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AttributeHelperEngine.cs:140)
    8. Unloading broken assembly /Applications/Unity/Hub/Editor/2018.4.6f1/Unity.app/Contents/UnityExtensions/Unity/GUISystem/Editor/UnityEditor.UI.dll, this assembly can cause crashes in the runtime
    9.  
    I suspect this has something to do with .NET framework versions, but I'm not very familiar with the .NET mess; any clues to what I should be looking for? The project uses .NET 4.x runtime and API compatibility level on Unity 2018.4.6. My plan B at the moment is to use another serializer, but if there is a way to get this working reliably, it would save time.