I was having trouble today with some OpenRasta tests using the InMemoryHost. The tests passed when run in isolation (i.e. together but as their own unit), but when run in the context of the entire test assembly the tests failed with this exception being thrown:

TestFixture failed: System.TypeInitializationException : The type initializer for 'OpenRasta.Hosting.HostManager' threw an exception.
----> OpenRasta.DI.DependencyResolutionException : No type registered for ILogger
at OpenRasta.Hosting.HostManager.RegisterHost(IHost host)
at OpenRasta.Hosting.InMemory.InMemoryHost..ctor(IConfigurationSource configuration) in c:\src\openrasta-stable\src\openrasta-core\src\OpenRasta\Hosting\InMemory\InMemoryHost.cs:line 19

The nature of the error made me suspect a static type somewhere. I cracked open the source for HostManager (via GitHub) and tracked it down to the DependencyManager. So for anyone else suffering this issue, here’s how to solve it. Calling DependencyManager.SetResolver() is the cause, so if you have a test that does this then you need to make sure you call Dependencymanager.UnsetResolver() afterwards. Simple.

I should admit that I’ve only myself to blame for this, because it’s written right here in the documentation. Schoolboy error, right?

Anyway. Now I’ve got 46 tests passed, 0 failed. Lovely.

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>