Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

(Case 1082102) 2018.3.0b1: ReflectionTypeLoadException in player when using reflection

Discussion in '2018.3 Beta' started by SINe-DEPRECATED, Sep 14, 2018.

  1. SINe-DEPRECATED

    SINe-DEPRECATED

    Joined:
    Oct 15, 2016
    Posts:
    13
    Previously the code below would execute without exceptions in 2018.2. However, in 2018.3 beta, it throws the exception in standalone players. I'm not sure if this is a bug, as I'm unfamiliar with the minutiae of the changes to the backend.


    Code (CSharp):
    1.  
    2. using System;
    3. using System.Reflection;
    4.  
    5. using UnityEngine;
    6.  
    7. public class GetTypes : MonoBehaviour
    8. {
    9.   void Start()
    10.   {
    11.     try
    12.     {
    13.       foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
    14.       {
    15.         foreach (Type t in a.GetTypes())
    16.         {
    17.           Debug.LogFormat("Type: {0}", t.Name);
    18.         }
    19.       }
    20.     }
    21.     catch (ReflectionTypeLoadException e)
    22.     {
    23.       foreach (Type iType in e.Types)
    24.       {
    25.         Debug.LogErrorFormat("Error Type: {0}", iType.AssemblyQualifiedName);
    26.       }
    27.     }
    28.   }
    29. }
    30.  
     
  2. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    Could you share your Player.log with the logging of the exceptions being thrown?
     
  3. SINe-DEPRECATED

    SINe-DEPRECATED

    Joined:
    Oct 15, 2016
    Posts:
    13
    I've attached two log files.

    "output_log (caught).txt" is from the above code.
    "output_log (uncaught).txt" is from the below code, without catching the exception.

    Code (CSharp):
    1. using System;
    2. using System.Reflection;
    3.  
    4. using UnityEngine;
    5.  
    6. public class GetTypes : MonoBehaviour
    7. {
    8.   void Start()
    9.   {
    10.     foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
    11.     {
    12.       foreach (Type t in a.GetTypes())
    13.       {
    14.         Debug.LogFormat("Type: {0}", t.Name);
    15.       }
    16.     }
    17.   }
    18. }
    19.  
     

    Attached Files:

  4. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    It is unclear from the logs what the issue. Could you report a bug and attach a small repro project for this issue, so it can be investigated? Thanks.
     
  5. SINe-DEPRECATED

    SINe-DEPRECATED

    Joined:
    Oct 15, 2016
    Posts:
    13
    I've done exactly that, and changed the title of the thread to the title of the bug report.
     
    LeonhardP and lukaszunity like this.
  6. falkj17

    falkj17

    Joined:
    Sep 11, 2017
    Posts:
    9
    I've seen exactly the same issue when using Jetbrains rider. When starting up Unity, Rider will add a plugin to Unity which fails to load with the following error:
    Code (CSharp):
    1. Unloading broken assembly Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll, this assembly can cause crashes in the runtime
    2.  
    When trying to iterate over all assemblies and getting the types in these assemblies, it will also iterate over the JetBrains plugin. After excluding it and not calling GetTypes on this assembly, it worked. It would be interesting to know, whether you also have Rider installed.
     
  7. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    This should only happen in the editor. The latest version of Rider EAP should have this issue fixed.
     
  8. falkj17

    falkj17

    Joined:
    Sep 11, 2017
    Posts:
    9
    Updating Rider worked, thanks!
     
    LeonhardP likes this.