My unit tests fails when they get here:
var y = AppDomain.CurrentDomain
.GetAssemblies()
.Where(a => !a.GlobalAssemblyCache)
.SelectMany(a => a.GetExportedTypes()
.Where(t => t.IsClass && typeof(ITypeRenderer).IsAssignableFrom(t)))
.ToArray();
But when I run the test with the debugger attached, it does not fail.
I guess it has to do something with reflection permissions and all that jazz, any idea?
The exception is:
Initialization method MyUnitTestProject.UnitTest.Init threw exception.
System.NotSupportedException: System.NotSupportedException: The
invoked member is not supported in a dynamic assembly..
The exception happens at:
System.Reflection.Emit.InternalAssemblyBuilder.GetExportedTypes()
Thanks.
Well, the error message does say “The invoked member is not supported in a dynamic assembly”. Obviously, when you’re running the tests outside of the debugger, something is causing a dynamic assembly to be created in the same AppDomain as where the tests are running.
Equally (hopefully) obviously, a check for
IsDynamicto exclude such assemblies (in the same way that you exclude GAC assemblies) should avoid the error.