I'm getting a peculiar result with some unit tests ...
When running the unit test (in visual studio) it fails, so I re-run the unit test with the debugger attached to look deeper in to the issue.
This time it passes.
The error is:
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type SomeCustomType, key "" ---> System.TypeLoadException: Could not load type 'SomeOtherTypeThatSomeCustomTypeDependsOn'.
I'm not sure if this is the right place to ask but I figured i'd ask in case any suggestions come up.
Why would a type not be "loadable" when a debugger is not present as opposed to when it is?
Seems odd to me.
I am using the same build and config each time the only difference is i either push the "Run tests" button or the "Debug tests" button in the IDE.
Small bit of additional info... i have managed to pull the unit test in question apart and find this ...
_kernel = new RhinoMocksMockingKernel();
_locator = new NinjectAdapter.NinjectServiceLocator(_kernel);
CommonService.Locator = _locator;
BounceService service = CommonService.Locator.GetInstance<BounceService>();
The "when" (above) fails with an exception which reads ...
Test method BounceServiceTest.BounceService_Object_Can_Be_Constructed threw exception:
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type BounceService, key "" ---> System.TypeLoadException: Could not load type '...SubscriberContext' from assembly '...Business, Version=184.108.40.206,
... this only occurs when the debugger is NOT attached.
Are you running your tests with Code Coverage gathering enabled (or some of the other data collection tools)? If so, your codeunder test might be stuck in a proxy or might have been made public without you knowing it. When you run your test in the debugger,
Code Coverage and some of the other data collectors are automatically disabled.
This might explain the behavior you're seeing. We've had similar issues with Activator.CreateInstance and other Reflection based code that made assumptions on the fact whether things were public or private in the past with Code Coverage enabled.