Question

I have a unit test written with xUnit, AutoFixture, using AutoFixture Idioms GuardClauseAssertion to check for guard clauses in my assemblies' classes:

[InlineData(typeof (ProjectOneClass))]
[InlineData(typeof (ProjectTwoClass))]
[InlineData(typeof (ProjectThreeClass))]
[InlineData(typeof (ProjectFourClass))]
[InlineData(typeof (ProjectFiveClass))]
[Theory(DisplayName = "Classes guard against null arguments in assemblies")]
public void GuardAgainstNullArgumentsInAssemblies(Type assemblyHintType)
{
    // arrange
    IFixture fixture = new Fixture().Customize(new AutoMoqCustomization());
    fixture.Behaviors.Add(new TracingBehavior());
    var assertion = new GuardClauseAssertion(fixture);

    // assert
    assertion.Verify(assemblyHintType.Assembly.GetTypes()
        .Where(t =>
            !t.Name.Equals("MyWebServices") &&
            !t.Name.Equals("MyComputer") &&
            !t.Name.Equals("MyProject") &&
            !t.Name.Equals("MyApplication") &&
            !t.IsInterface &&
            !t.IsGenericType &&
            !t.IsCompilerGenerated() &&
            !t.IsStaticClass()
        ));
}

I make my assertion with filters to focus the unit test on only the appropriate classes I wrote, and use hint types to target specific assemblies. I pass these hint types in using InlineData(typeof(...)), so that the test is once for each hint type.

The tests pass for 3 out of the 5 tests, after having a few test runs which pointed out code where I forgot to put in null guards, but the other two tests yield the following exception:

System.BadImageFormatException An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at

System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type) at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() at System.Reflection.Emit.TypeBuilder.CreateType() at Ploeh.AutoFixture.Idioms.GuardClauseAssertion.AutoGenericArgument.get_Value() at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray(IEnumerable1 source) at Ploeh.AutoFixture.Idioms.GuardClauseAssertion.AutoGenericMethod.get_Value() at Ploeh.AutoFixture.Idioms.GuardClauseAssertion.Verify(MethodInfo methodInfo) at Ploeh.AutoFixture.Idioms.IdiomaticAssertion.Verify(MethodInfo[] methodInfos) at Ploeh.AutoFixture.Idioms.IdiomaticAssertion.Verify(Type type) at Ploeh.AutoFixture.Idioms.IdiomaticAssertion.Verify(Type[] types) at NullGuardTests.GuardAgainstNullArgumentsInNonModelAssemblies(Type assemblyHintType) in NullGuardTests.cs: line 58

I add TracingBehavior to the the IFixture instance for more visibility, and it shows:

Requested: Infrastructure.Logging.IErrorAggregator errorAggregator
  Requested: Ploeh.AutoFixture.Kernel.SeededRequest

... and on and on and on...

I've looked at the very first item and the very last item in this long trace to try and figure out how they are different from the very first/last items shown in the successful tests' traces, but I haven't been able to find any meaningful differences.

I'm assuming that the last item in the trace is the last activity from the IFixture before the exception.

How do I get more visibility into an exception like this, beyond what I've done so far?

  • Every targeted assembly is targeting .NET 4.0
  • Every targeted assembly has the same settings in the Build configuration (AnyCPU)
  • Every targeted assembly is written in VB.NET (although the unit test is in C#)

Ideas? Thank you in advance.

Update 29 MAR 2014

I still haven't been able to figure out what's happening here, but I'm hoping that leaving the question up will at least be a sanity check for someone else with the same problem, who discovers this question here. Workload permitting, I'll work on submitting a repro.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top