diff --git a/src/WireMock.Net.Shared/Util/TypeLoader.cs b/src/WireMock.Net.Shared/Util/TypeLoader.cs index 60ba7fdd..2f631297 100644 --- a/src/WireMock.Net.Shared/Util/TypeLoader.cs +++ b/src/WireMock.Net.Shared/Util/TypeLoader.cs @@ -119,13 +119,21 @@ private static bool TryFindTypeInDlls(string? implementationTypeFull private static bool TryGetImplementationTypeByInterfaceAndOptionalFullName(Assembly assembly, string? implementationTypeFullName, [NotNullWhen(true)] out Type? type) { - type = assembly - .GetTypes() - .FirstOrDefault(t => - typeof(T).IsAssignableFrom(t) && !t.GetTypeInfo().IsInterface && - (implementationTypeFullName == null || string.Equals(t.FullName, implementationTypeFullName, StringComparison.OrdinalIgnoreCase)) - ); - - return type != null; + try + { + type = assembly + .GetTypes() + .FirstOrDefault(t => + typeof(T).IsAssignableFrom(t) && !t.GetTypeInfo().IsInterface && + (implementationTypeFullName == null || string.Equals(t.FullName, implementationTypeFullName, StringComparison.OrdinalIgnoreCase)) + ); + + return type != null; + } + catch + { + type = null; + return false; + } } } \ No newline at end of file