Skip to content

Commit a3b7d79

Browse files
committed
Resolve the type loading problem when search types
in a more polite way.
1 parent a4f5ea2 commit a3b7d79

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

UInspectorPlus/Helpers.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,21 @@ private static MethodInfo FindMethod(Type fromType, string methodName, Type dele
604604
);
605605
}
606606

607+
public static IEnumerable<Type> LooseGetTypes(Assembly assembly) {
608+
for(int retries = 0; retries < 2; retries++)
609+
try {
610+
return assembly.GetTypes();
611+
} catch(ReflectionTypeLoadException typeLoadEx) {
612+
// Retry first!
613+
if(retries < 1) continue;
614+
// Some types don't like to be loaded, then ignore them.
615+
return from type in typeLoadEx.Types
616+
where type != null
617+
select type;
618+
}
619+
return null; // Should not reach here
620+
}
621+
607622
[MenuItem("Window/Inspector+")]
608623
public static void ShowInspectorPlus() {
609624
EditorWindow.GetWindow(typeof(InspectorPlus));

UInspectorPlus/TypeMatcher.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,12 @@ public void Draw() {
5555
}
5656

5757
private void InitSearch() {
58-
for(int retries = 0; retries < 2; retries++) {
59-
try {
60-
if(searchedTypes.Count <= 0)
61-
searchedTypes.UnionWith(
62-
from assembly in AppDomain.CurrentDomain.GetAssemblies()
63-
from type in assembly.GetTypes()
64-
select type
65-
);
66-
break;
67-
} catch(Exception ex) {
68-
Helper.PrintExceptionsWithInner(ex);
69-
}
70-
}
58+
if(searchedTypes.Count > 0) return;
59+
searchedTypes.UnionWith(
60+
from assembly in AppDomain.CurrentDomain.GetAssemblies()
61+
from type in Helper.LooseGetTypes(assembly)
62+
select type
63+
);
7164
}
7265

7366
private void DoSearch() {

0 commit comments

Comments
 (0)