Skip to content

Commit 9fcc9ad

Browse files
authored
Add additional try-catch to TypeLoader logic (#1352)
1 parent 865bbf2 commit 9fcc9ad

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/WireMock.Net.Shared/Util/TypeLoader.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ private static bool TryFindTypeInDlls<TInterface>(string? implementationTypeFull
119119

120120
private static bool TryGetImplementationTypeByInterfaceAndOptionalFullName<T>(Assembly assembly, string? implementationTypeFullName, [NotNullWhen(true)] out Type? type)
121121
{
122-
type = assembly
123-
.GetTypes()
124-
.FirstOrDefault(t =>
125-
typeof(T).IsAssignableFrom(t) && !t.GetTypeInfo().IsInterface &&
126-
(implementationTypeFullName == null || string.Equals(t.FullName, implementationTypeFullName, StringComparison.OrdinalIgnoreCase))
127-
);
128-
129-
return type != null;
122+
try
123+
{
124+
type = assembly
125+
.GetTypes()
126+
.FirstOrDefault(t =>
127+
typeof(T).IsAssignableFrom(t) && !t.GetTypeInfo().IsInterface &&
128+
(implementationTypeFullName == null || string.Equals(t.FullName, implementationTypeFullName, StringComparison.OrdinalIgnoreCase))
129+
);
130+
131+
return type != null;
132+
}
133+
catch
134+
{
135+
type = null;
136+
return false;
137+
}
130138
}
131139
}

0 commit comments

Comments
 (0)