Skip to content

Commit 5104878

Browse files
committed
Fixed a bug in GetTypesToTest - the tests would fail if .net runtime failed to load some of the types
1 parent 964d474 commit 5104878

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

ConventionTests/ConventionTests.NUnit.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,22 @@ protected virtual Assembly[] GetAssembliesToScan(ConventionData data)
147147
protected virtual Type[] GetTypesToTest(ConventionData data)
148148
{
149149
return
150-
GetAssembliesToScan(data).SelectMany(a => a.GetTypes()).Where(data.Types.Invoke).OrderBy(t => t.FullName)
151-
.ToArray();
152-
}
153-
}
150+
GetAssembliesToScan(data).SelectMany(GetTypesSafely).Where(data.Types.Invoke).OrderBy(t => t.FullName)
151+
.ToArray();
152+
}
153+
154+
private static IEnumerable<Type> GetTypesSafely(Assembly assembly)
155+
{
156+
try
157+
{
158+
return assembly.GetTypes();
159+
}
160+
catch (ReflectionTypeLoadException ex)
161+
{
162+
return ex.Types.Where(x => x != null);
163+
}
164+
}
165+
}
154166

155167
public abstract class WindsorConventionTest<TDiagnostic> : WindsorConventionTest<TDiagnostic, IHandler>
156168
where TDiagnostic : class, IDiagnostic<IEnumerable<IHandler>>, IDiagnostic<object>

0 commit comments

Comments
 (0)