Skip to content

Commit

Permalink
fix ReflectionTypeLoadException when scanning assemblies
Browse files Browse the repository at this point in the history
for WurstMod 2.2.0 and the new TNH alpha
  • Loading branch information
Ash committed Jul 20, 2021
1 parent da3b24d commit 4952ff9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
## [0.4.2]
### Fixed
- MonoMod patchers will no longer throw exceptions when BepInEx.MonoModLoader is used
- A ReflectionTypeLoadException will no longer cause a crash

## [0.4.0]
### Added
Expand Down
14 changes: 13 additions & 1 deletion src/Deli.Patcher/src/Common/Stage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx.Logging;
using Deli.Immediate;
Expand Down Expand Up @@ -163,7 +164,18 @@ protected virtual void TypeLoader(Stage stage, Mod mod, Type type)

protected void AssemblyLoader(Stage stage, Mod mod, Assembly assembly)
{
foreach (var type in assembly.GetExportedTypes())
IEnumerable<Type> types;
try
{
types = assembly.GetExportedTypes();
}
catch (ReflectionTypeLoadException e)
{
Logger.LogWarning($"Could not load all types from {assembly} within {mod}.");
types = e.Types.Where(x => x != null);
}

foreach (var type in types)
{
TypeLoader(stage, mod, type);
}
Expand Down

0 comments on commit 4952ff9

Please sign in to comment.