Skip to content

Commit

Permalink
Do not crash the plugin packer if Assembly.GetTypes crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Jun 21, 2024
1 parent 9d84ec4 commit 05f3539
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion BTCPayServer.PluginPacker/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -109,9 +110,22 @@ private static async Task CreateShasums(string exec, string sha256dirs, string o

private static Type[] GetAllExtensionTypesFromAssembly(Assembly assembly)
{
return assembly.GetTypes().Where(type =>
return GetLoadableTypes(assembly).Where(type =>
typeof(IBTCPayServerPlugin).IsAssignableFrom(type) &&
!type.IsAbstract).ToArray();
}
static Type[] GetLoadableTypes(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException(nameof(assembly));
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
return e.Types.Where(t => t != null).ToArray();
}
}
}
}

0 comments on commit 05f3539

Please sign in to comment.