Skip to content

Commit 79d1671

Browse files
committed
Fixed crashing if some types fail to load in an assembly
1 parent b229517 commit 79d1671

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

BepInEx.IPALoader/IllusionInjector/PluginManager.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static IEnumerable<IPlugin> LoadPluginsFromFile(string file, string exeN
5959
{
6060
var assembly = Assembly.LoadFrom(file);
6161

62-
foreach (var t in assembly.GetTypes())
62+
foreach (var t in GetTypesSafe(assembly))
6363
if (typeof(IPlugin).IsAssignableFrom(t))
6464
try
6565
{
@@ -93,6 +93,21 @@ private static IEnumerable<IPlugin> LoadPluginsFromFile(string file, string exeN
9393
return plugins;
9494
}
9595

96+
private static IEnumerable<Type> GetTypesSafe(Assembly assembly)
97+
{
98+
try
99+
{
100+
return assembly.GetTypes();
101+
}
102+
catch (ReflectionTypeLoadException e)
103+
{
104+
IPALoader.Logger.LogWarning("Could not load some types from assembly " + assembly.FullName + " - check debug log for details");
105+
foreach (var eLoaderException in e.LoaderExceptions)
106+
IPALoader.Logger.LogDebug(eLoaderException);
107+
return e.Types.Where(x => x != null);
108+
}
109+
}
110+
96111
public class AppInfo
97112
{
98113
private static readonly HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);

0 commit comments

Comments
 (0)