Twitter GitHub Facebook Instagram dirv.me

Daniel Irvine on building software

OpenRasta testing wierdness

24 June 2011

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-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.

About the author

Daniel Irvine is a software craftsman at 8th Light, based in London. These days he prefers to code in Clojure and Ruby, despite having been a C++ and C# developer for the majority of his career.

For a longer bio please see danielirvine.com. To contact Daniel, send a tweet to @d_ir or use the comments section below.

Twitter GitHub Facebook Instagram dirv.me