Skip to content

Commit 5891929

Browse files
committed
Fix exception where we would try to load assemblies which can't be loaded
1 parent 583de29 commit 5891929

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Reflection;
2+
3+
namespace ApiEase.Core.Extensions;
4+
5+
public static class AssemblyExtensions
6+
{
7+
public static Type[] GetLoadableTypes(this Assembly assembly)
8+
{
9+
try
10+
{
11+
return assembly.GetTypes();
12+
}
13+
catch (ReflectionTypeLoadException ex)
14+
{
15+
return ex.Types.Where(t => t is not null).ToArray()!;
16+
}
17+
}
18+
}

ApiEase.Core/Extensions/IServiceCollectionsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void AddDynamicClients(this IServiceCollection services, IConfigur
4949
private static IEnumerable<Type> GetDynamicClientInterfaces()
5050
{
5151
return AppDomain.CurrentDomain.GetAssemblies()
52-
.SelectMany(assembly => assembly.GetTypes())
52+
.SelectMany(assembly => assembly.GetLoadableTypes())
5353
.Where(t =>
5454
t.IsInterface &&
5555
typeof(IBaseClient).IsAssignableFrom(t) &&

0 commit comments

Comments
 (0)