supyrb / signals

❇ A typesafe, lightweight messaging system for Unity with UPM Support.

Home Page:https://github.com/supyrb/signals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeLoadException in Signlas Window with Unity 2019.3

Froghut opened this issue · comments

I get the following exception when clicking on Update Signals List:
ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.

System.Reflection.Assembly.GetTypes () (at <437ba245d8404784b9fbab9b439ac908>:0)
Supyrb.SignalReflectionHelper.GetAllDerivedClasses[T] (System.Collections.Generic.List`1[System.Type]& list, System.Reflection.Assembly assembly) (at Library/PackageCache/com.supyrb.signals@d761732506/Scripts/Editor/SignalReflectionHelper.cs:32)
Supyrb.SignalReflectionHelper.GetAllDerivedClasses[T] (System.Collections.Generic.List`1[System.Type]& list) (at Library/PackageCache/com.supyrb.signals@d761732506/Scripts/Editor/SignalReflectionHelper.cs:26)
Supyrb.SignalsEditorDatabase.UpdateDatabase () (at Library/PackageCache/com.supyrb.signals@d761732506/Scripts/Editor/SignalsEditorDatabase.cs:67)
Supyrb.SignalsTreeView.UpdateSignalData () (at Library/PackageCache/com.supyrb.signals@d761732506/Scripts/Editor/SignalsTreeView.cs:53)
Supyrb.SignalsTreeViewWindow.DoFooter () (at Library/PackageCache/com.supyrb.signals@d761732506/Scripts/Editor/SignalsTreeViewWindow.cs:142)
Supyrb.SignalsTreeViewWindow.OnGUI () (at Library/PackageCache/com.supyrb.signals@d761732506/Scripts/Editor/SignalsTreeViewWindow.cs:98)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <d0ffe769b7a34b4cac3a7cdc5c696293>:0)
UnityEditor.HostView.Invoke (System.String methodName) (at <d0ffe769b7a34b4cac3a7cdc5c696293>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <d0ffe769b7a34b4cac3a7cdc5c696293>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <d0ffe769b7a34b4cac3a7cdc5c696293>:0)
UnityEditor.DockArea.OldOnGUI () (at <d0ffe769b7a34b4cac3a7cdc5c696293>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Boolean canAffectFocus) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean canAffectFocus) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.EventDispatcher.OpenGate () (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <57fa7f4ad1c34ed185465e0a9f71c244>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <59837000ebf54955a9cb1d31caa86097>:0)

I get that exception on Assembly.GetTypes() for "Microsoft.CodeAnalysis.Scripting" since 2019.3, personally I just fix it by ignoring that exception.

Hi @Froghut,

thanks a lot for the bug report. Seems to be related to this issue: dotnet/roslyn#9417

Since the issue is quite old, I guess the best way is to ignore all assemblys that start with Microsoft.*, since those will have no defined signals in them. I'll get on that right away :)

Alright, I just went on to ignore processing all libraries that are outside the project folder. Those won't be relevant for searching for Signals classes (except when Unity itself decides to use the package), so I guess that is a nice optimization for now. Can you check if that fixes your problem? I sadly can't reproduce the problem, even though I'm testing on 2019.3.2f1.

I did not realize this is a general problem in Unity 2019. I found out the offending assembly is actually part of the unity package "Code Analysis" which is a dependency of the "Immediate Window" package I was using.
To come back to your fix, because the assembly is pat of a package it resides in the Library folder so is still checked.

Snap! I already though, that this might be tied to the code analysis package. Thanks for the analysis, I'll do a repro and will fix the problem.

I was able to reproduce the problem and blacklisted Microsoft.CodeAnalysis.* to avoid reading that assembly. That fixed the issue for me. Can you check as well? :)

I wasn't superhappy with the solution, so I included a try catch block which handles the exception. This way, future buggy assemblies should not break the update logic.

If you're interested, there is an issue filed for the very assembly that created a problem in our case: https://issuetracker.unity3d.com/issues/reflectiontypeloadexception-is-thrown-when-retrieving-assembly-types-in-project-that-contains-immediate-window-package

@Froghut Is the problem solved for you now? Version 0.4.3 should be safe to use again.

Yes, works! And thanks for the link to issue.

Sure thing, thanks for reporting and testing the issue :)