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

ReflectionTypeLoadException in .net4.x with System.Reflection.Assembly.GetTypes ()

Discussion in '2018.1 Beta' started by ahmidou, Mar 23, 2018.

  1. ahmidou

    ahmidou

    Joined:
    Sep 17, 2012
    Posts:
    87
    Hi, I'm getting this error everywhere System.Reflection.Assembly.GetTypes () is called.
    It happens with Cinemachine(I manage to fix it with some try/catch) and the Timeline Playable Wizard,
    but also with the editor's UI which makes it quite unresponsive, prone to visual errors and crash/freeze.
    I found a few threads about similar error but not that much, so I'm wondering what would be the causes and how can I safely fix it?

    Thanks

    ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
    System.Reflection.Assembly.GetTypes () (at <e1a80661d61443feb3dbdaac88eeb776>:0)
    UnityEngine.Experimental.UIElements.Factories.DiscoverFactories () (at C:/buildslave/unity/build/Modules/UIElements/UXML/VisualElementFactory.cs:58)
    UnityEngine.Experimental.UIElements.Factories.RegisterFactory (System.String fullTypeName, System.Func`3[T1,T2,TResult] factory) (at C:/buildslave/unity/build/Modules/UIElements/UXML/VisualElementFactory.cs:31)
    UnityEngine.Experimental.UIElements.Factories.RegisterFactory[T] (System.Func`3[T1,T2,TResult] factory) (at C:/buildslave/unity/build/Modules/UIElements/UXML/VisualElementFactory.cs:37)
    UnityEditor.Experimental.UIElements.UXMLEditorFactories.RegisterAll () (at C:/buildslave/unity/build/Editor/Mono/UIElements/Controls/UXMLEditorFactories.cs:18)
    UnityEditor.GUIView.get_panel () (at C:/buildslave/unity/build/Editor/Mono/GUIView.cs:42)
    UnityEditor.GUIView.get_visualTree () (at C:/buildslave/unity/build/Editor/Mono/GUIView.cs:56)
    UnityEditor.GUIView.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/GUIView.cs:170)
    UnityEditor.AppStatusBar.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/GUI/AppStatusBar.cs:16)
     
    Last edited: Mar 23, 2018
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
    In the particular case of UIElements, it is calling GetTypes() on each user assembly. Some of the types in the user assemblies could not be loaded (maybe a static constructor is throwing an exception?).
     
    Wayne-himiko likes this.
  3. ahmidou

    ahmidou

    Joined:
    Sep 17, 2012
    Posts:
    87
    Thanks Patrick,
    Any Idea how I can track this?
     
  4. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    57
  5. jgilbert

    jgilbert

    Joined:
    Aug 20, 2014
    Posts:
    10
    Just as some supporting information, we had this same issue. Like patrickf stated, catching the exception and inspecting the LoaderExceptions makes quick work of figuring out which types are causing the issue. For us, it was because we were "cheating" with the older runtime using a generic with an explicit layout to get around boxing/unboxing for some networking code and flag checking:


    [StructLayout(LayoutKind.Explicit)]
    private struct EnumBuffer<T>
    {
    [FieldOffset(0)]
    public T Enum0;
    [FieldOffset(0)]
    public Int32 Int0;
    [FieldOffset(0)]
    public Int16 Short0;
    [FieldOffset(0)]
    public byte Byte0;
    }