Unity Exceptions with Unit Tests in VS2010

Jul 21, 2010 at 9:21 PM
Edited Jul 21, 2010 at 9:22 PM

I have a project which makes heavy use of Unity along with a lot of unit tests.

Recently, without a known change, the tests suddenly started failing with (unity) exceptions about a type not being able to load (the type was different for different tests).  I verified that my configuration is correct.

I then debugged the same exact tests and they ran without any errors.  After the test run, without a debugger attached, I ran the same tests yet again and they work.

What effect does the debugger have on this and why would it suddenly start to work after having attached it to a test run.

Jul 22, 2010 at 5:58 AM

I don't have an explanation for you, but I have, very occasionally, seen similar weirdness on development machines. I don't know if the debugger leaves the OS in a weird state, or something just gets stuck in the CLR or what. Oh, and I've seen this on non-Unity projects as well. I expect now that it's cleared you'll never see it again.

Another possibility could be bad hardware. Overheading or RAM going bad can cause glitches in the system that result in very, VERY strange errors.

But I'm just guessing at this point.


Jul 22, 2010 at 2:05 PM
Edited Jul 22, 2010 at 2:06 PM
I appreciate the thoughts. I can actually reproduce this every time if I simply re-run the tests without a debugger but with a different set of tests.

Essentially, if I run a set of tests, debug the ones that failed, they will pass with the debugger attached and then continue to pass (even without a debugger) so long as I keep the same tests selected. As soon as I go back to my test list and select all of my tests again the failed result occurs.

Our build machine does not seem to have this issue. Which would make it seems like it is my machine that is messed up. The only extensions I have installed at: Productivity Power Tools, Spell Checker, Ghost Doc, and the tangible T4 editor.

Here are a couple of the errors I see:
Test method XXXX threw exception:
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "XXXXXXX", name = "". Exception message is: The current build operation (build key Build Key[YYYYYYYY, null]) failed: The current type, YYYYYYYY, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build KeyYYYYYYYY, null]) failed: The current type, YYYYYYYYYY, is an interface and cannot be constructed. Are you missing a type mapping? (Strategy type BuildPlanStrategy, index 3) ---> System.InvalidOperationException: The current type, YYYYYYYYYYY, is an interface and cannot be constructed. Are you missing a type mapping?

Test method XXXXXXX threw exception:
System.MissingMethodException: Method not found: 'System.Collections.Generic.List`1<!0> SomeClass`2.SomeType(System.Guid, System.Collections.Generic.List`1<!0>, SomeType ByRef, System.Collections.Generic.List`1<!1> ByRef)'.