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

Resolved TypeLoadException, how to deal with it?

Discussion in 'Scripting' started by privatecontractor, Jul 29, 2023.

  1. privatecontractor

    privatecontractor

    Joined:
    Nov 29, 2020
    Posts:
    42
    HI all. Working on compilation of my scripts to *.dll.... Long story short,
    (1) after importing to created folder: "MyAwesomeAsset\Plugins";
    (2) all classes working correctly;
    (3) except one, created as EditorWindow, after clicking assigned MenuItem, reciving spam error:
    (4) TypeLoadException: Could not resolve type with token 01000018 from typeref (expected class 'System.Runtime.CompilerServices.DefaultInterpolatedStringHandler' in assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at <5f40cdb07bd44d76a23dad985a4ec283>:0)

    Ay help, how to deal with it?

    * UnityEditor.dll &&UnityEngine.dll are included in assemblies
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    One thing I can imagine, since you mention EditorWindow, is that the DLL may need to be flagged as editor-only in the Inspector. If you need both Editor and Runtime support I believe you need to create two separate DLL projects / files.

    Also, you may be using features in your DLL that aren't supported in Unity's .NET implementation (based on Mono). According to google the first couple hits that mention the error message are all related to Microsoft Azure.
     
  3. privatecontractor

    privatecontractor

    Joined:
    Nov 29, 2020
    Posts:
    42
    after commenting // uncommenting lots off lines.... find line that causes problem.... it's working as normal script... but as *.dll causes Error.... any idea how to solve this crap??


    Code (CSharp):
    1.                     for (int i = 0; i < m_amountOfRooms; i++)
    2.                     {
    3.                         m_predefinedRooms[i] = (Room_SO)EditorGUILayout.ObjectField($"Room [{i}]", m_predefinedRooms[i], typeof(Room_SO), true, gUILayoutOption);
    4.                         EditorGUILayout.Space();
    5.                     }
     
  4. privatecontractor

    privatecontractor

    Joined:
    Nov 29, 2020
    Posts:
    42
    OMG.... its because: $"Room [{i}]" ..... o_O
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Perhaps... but since it is already a given that
    EditorGUILayout
    won't be in non-editor assemblies, why not start with removing that class first?
     
  6. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,057
    System.Runtime.CompilerServices.DefaultInterpolatedStringHandler
    is .NET 6 or later.
    https://learn.microsoft.com/en-us/d...defaultinterpolatedstringhandler?view=net-7.0

    Unity is still based on .NET Standard 2.1 and Framework 4.8
    https://docs.unity3d.com/Manual/dotnetProfileSupport.html

    My guess is that this has to do with the improved string interpolation in later versions of .NET
    But since this is not available with Unity's .NET profile, it won't know the type.

    Try compiling your DLL with .NET Standard 2.1 (which is the default profile setting for a Unity project)
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    MaskedMouse likes this.
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Exactly.

    And to add to that: if you plan on making an asset store asset: don't distribute your asset's code in DLLs!
    For one, a lot of devs actually check for and skip over any tool that does not provide the code because it's a black box they can't easily change.
    Secondly the DLL protects nothing. They're easily decompiled to readable, annotated C# code with a double-click in a modern IDE.

    The only time I really enjoyed working with a DLL was with code that could run standalone as a command line tool, and I could use regular NUnit tests. The turnaround time for compiling and testing was close to zero.