microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6.01k stars 2.12k forks source link

Constant spam of ReflectTypeLoadException errors #5419

Closed hendryems closed 5 years ago

hendryems commented 5 years ago

Describe the bug

A constant error spam (5 errors per second) originating from the MRTK editor UI that makes the app unusable in the editor and drastically slows Unity's performance.

image

Looks like this is the callstack:

ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
  at (wrapper managed-to-native) System.Reflection.Assembly.GetTypes(System.Reflection.Assembly,bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at Microsoft.MixedReality.Toolkit.Utilities.Facades.ServiceFacadeEditor+<>c.<InitializeServiceInspectorLookup>b__17_0 (System.Reflection.Assembly assembly) [0x00000] in <ff1d1f21579742b3b5d8b352022b1ce8>:0 
  at System.Linq.Parallel.SelectManyQueryOperator`3+SelectManyQueryOperatorEnumerator`1[TLeftInput,TRightInput,TOutput,TLeftKey].MoveNext (TOutput& currentElement, System.Linq.Parallel.Pair`2[TLeftKey,System.Int32]& currentKey) [0x00061] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.SelectQueryOperator`2+SelectQueryOperatorEnumerator`1[TInput,TOutput,TKey].MoveNext (TOutput& currentElement, TKey& currentKey) [0x00008] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.WhereQueryOperator`1+WhereQueryOperatorEnumerator`1[TInputOutput,TKey].MoveNext (TInputOutput& currentElement, TKey& currentKey) [0x00051] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.SelectQueryOperator`2+SelectQueryOperatorEnumerator`1[TInput,TOutput,TKey].MoveNext (TOutput& currentElement, TKey& currentKey) [0x00008] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.PipelineSpoolingTask`2[TInputOutput,TIgnoreKey].SpoolingWork () [0x00042] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.SpoolingTaskBase.Work () [0x0005d] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.QueryTask.BaseWork (System.Object unused) [0x00015] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.QueryTask+<>c.<.cctor>b__10_0 (System.Object o) [0x00000] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Threading.Tasks.Task.InnerInvoke () [0x00025] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at System.Threading.Tasks.Task.Execute () [0x00010] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
Rethrow as AggregateException: One or more errors occurred.
  at System.Linq.Parallel.QueryTaskGroupState.QueryEnd (System.Boolean userInitiatedDispose) [0x00081] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.AsynchronousChannelMergeEnumerator`1[T].MoveNextSlowPath () [0x001c2] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.AsynchronousChannelMergeEnumerator`1[T].MoveNext () [0x00054] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at System.Linq.Parallel.QueryOpeningEnumerator`1[TOutput].MoveNext () [0x0002b] in <1b13ba6391c74847bbc3eddc86df7eee>:0 
  at Microsoft.MixedReality.Toolkit.Utilities.Facades.ServiceFacadeEditor.InitializeServiceInspectorLookup () [0x00109] in <ff1d1f21579742b3b5d8b352022b1ce8>:0 
  at Microsoft.MixedReality.Toolkit.Utilities.Facades.ServiceFacadeEditor.DrawGizmos (Microsoft.MixedReality.Toolkit.Utilities.Facades.ServiceFacade facade, UnityEditor.GizmoType type) [0x0002f] in <ff1d1f21579742b3b5d8b352022b1ce8>:0 
UnityEditor.Handles:Internal_FinishDrawingCamera()
UnityEditor.Handles:Internal_FinishDrawingCamera(Camera) (at C:\buildslave\unity\build\Editor\Mono\Handles.bindings.cs:50)
UnityEditor.Handles:DrawCameraStep2(Camera, DrawCameraMode) (at C:\buildslave\unity\build\Editor\Mono\Handles.cs:1341)
UnityEditor.SceneView:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\SceneView\SceneView.cs:1946)
System.Reflection.MonoMethod:InternalInvoke()
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
UnityEditor.HostView:Invoke(String, Object) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:342)
UnityEditor.HostView:Invoke(String) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:336)
UnityEditor.HostView:InvokeOnGUI(Rect, Rect) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:302)
UnityEditor.DockArea:DrawView(Rect, Rect, Boolean, Boolean, Boolean) (at C:\buildslave\unity\build\Editor\Mono\GUI\DockArea.cs:361)
UnityEditor.DockArea:OldOnGUI() (at C:\buildslave\unity\build\Editor\Mono\GUI\DockArea.cs:320)
UnityEngine.Experimental.UIElements.IMGUIContainer:DoOnGUI(Event, Matrix4x4, Rect, Boolean) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:244)
UnityEngine.Experimental.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Matrix4x4, Rect) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:438)
UnityEngine.Experimental.UIElements.IMGUIContainer:HandleIMGUIEvent() (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:412)
UnityEngine.Experimental.UIElements.ImmediateStylePainter:DrawImmediate(Action) (at C:\buildslave\unity\build\Modules\UIElements\ImmediateStylePainter.cs:113)
UnityEngine.Experimental.UIElements.IMGUIContainer:DoRepaint(IStylePainter) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:98)
UnityEngine.Experimental.UIElements.VisualElement:Repaint(IStylePainter) (at C:\buildslave\unity\build\Modules\UIElements\VisualElement.cs:862)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:PaintSubTree(VisualElement, Matrix4x4, Boolean, Boolean, Rect) (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:310)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:PaintSubTreeChildren(VisualElement, Matrix4x4, Boolean, Boolean, Rect) (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:328)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:PaintSubTree(VisualElement, Matrix4x4, Boolean, Boolean, Rect) (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:314)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:Update() (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:35)
UnityEngine.Experimental.UIElements.VisualTreeUpdater:UpdateVisualTree() (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeUpdater.cs:70)
UnityEngine.Experimental.UIElements.Panel:Repaint(Event) (at C:\buildslave\unity\build\Modules\UIElements\Panel.cs:507)
UnityEngine.Experimental.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel) (at C:\buildslave\unity\build\Modules\UIElements\UIElementsUtility.cs:230)
UnityEngine.Experimental.UIElements.UIElementsUtility:ProcessEvent(Int32, IntPtr) (at C:\buildslave\unity\build\Modules\UIElements\UIElementsUtility.cs:68)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:\buildslave\unity\build\Modules\IMGUI\GUIUtility.cs:179)
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
UnityEngine.DebugLogHandler:Internal_Log()
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
UnityEngine.Experimental.UIElements.IMGUIContainer:DoOnGUI(Event, Matrix4x4, Rect, Boolean) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:361)
UnityEngine.Experimental.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Matrix4x4, Rect) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:435)
UnityEngine.Experimental.UIElements.IMGUIContainer:HandleIMGUIEvent() (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:412)
UnityEngine.Experimental.UIElements.ImmediateStylePainter:DrawImmediate(Action) (at C:\buildslave\unity\build\Modules\UIElements\ImmediateStylePainter.cs:113)
UnityEngine.Experimental.UIElements.IMGUIContainer:DoRepaint(IStylePainter) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:98)
UnityEngine.Experimental.UIElements.VisualElement:Repaint(IStylePainter) (at C:\buildslave\unity\build\Modules\UIElements\VisualElement.cs:862)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:PaintSubTree(VisualElement, Matrix4x4, Boolean, Boolean, Rect) (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:310)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:PaintSubTreeChildren(VisualElement, Matrix4x4, Boolean, Boolean, Rect) (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:328)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:PaintSubTree(VisualElement, Matrix4x4, Boolean, Boolean, Rect) (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:314)
UnityEngine.Experimental.UIElements.VisualTreeRepaintUpdater:Update() (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeRepaintUpdater.cs:35)
UnityEngine.Experimental.UIElements.VisualTreeUpdater:UpdateVisualTree() (at C:\buildslave\unity\build\Modules\UIElements\VisualTreeUpdater.cs:70)
UnityEngine.Experimental.UIElements.Panel:Repaint(Event) (at C:\buildslave\unity\build\Modules\UIElements\Panel.cs:507)
UnityEngine.Experimental.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel) (at C:\buildslave\unity\build\Modules\UIElements\UIElementsUtility.cs:230)
UnityEngine.Experimental.UIElements.UIElementsUtility:ProcessEvent(Int32, IntPtr) (at C:\buildslave\unity\build\Modules\UIElements\UIElementsUtility.cs:68)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:\buildslave\unity\build\Modules\IMGUI\GUIUtility.cs:179)

To reproduce

Steps to reproduce the behavior:

Expected behavior

No errors

Screenshots

image

Your Setup (please complete the following information)

Target Platform (please complete the following information)

Additional context

The issue went away when we upgraded the project to Unity 2108.4.4f1; the latest LTS. Its not clear exactly what in Unity2018.3.10.

ritijain commented 5 years ago

var typesWithMyAttribute = from assembly in AppDomain.CurrentDomain.GetAssemblies().AsParallel() from classType in assembly.GetTypes() let attribute = classType.GetCustomAttribute(true) where attribute != null select new { ClassType = classType, Attribute = attribute };

assembly.GetTypes() is probably throwing an exception in Assets\MixedRealityToolkit\Inspectors\ServiceInspectors\ServiceFacadeInspector.cs. I have seen this issue in some apps which import natively built dll's in unity.

david-c-kline commented 5 years ago

this has been confirmed to be fixed in Unity 2018.4.

AdamMitchell-ms commented 5 years ago

@davidkline-ms , I'm seeing this on Unity 2018.4.5f. What precise build is known to have fixed this?

Should MRTK just implement the extension method workaround described here: https://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes

david-c-kline commented 5 years ago

I'm seeing this on Unity 2018.4.5f. What precise build is known to have fixed this?

Interesting. We had been testing on 2018.4.4. It is possible that the apparent fix was a timing change that may have regressed.