Today I was trying to debug an issue with some new code that we are working on. During my initial development all my tests worked and everything was fine. However, when I actually hooked up all the pieces and tried to run the new code as a full unit I was receiving the dreaded “StructureMap Exception Code: 202 No Default Instance defined for PluginFamily” exception.
At first glance I thought this was a very, very odd exception because I know my auto registration should have picked up the various dependencies. In order to better test and understand what may be causing the error I created a new integration test which mimicked my production code (without the multi-threading to remove that headache).
To fully explain, this code is a windows service which loads up multiple ‘features’ and each feature is loaded into their own AppDomain (which is part of the new feature) in order to protect from crashes and other fun stuff that comes with a multi-threaded windows service.
When I started to step through the code I got to the part where the 2nd AppDomain was being created. Prior to walking into that code I decided to do an ObjectFactory.WhatDoIHave() which will output all the registered components. Doing this showed me that all my components were in deed registered as desired. At this point I knew I was good, at least from the perspective of my main AppDomain.
When I let the code walk into the newly created AppDomain I again did a ObjectFactory.WhatDoIHave(), this time it showed me I had nothing registered. Problem found, not to solve it (which is a totally different post).
The point of this post is this. If you are using an IoC container and you load up multiple AppDomains make sure you perform your registration of your components for each AppDomain, if you do not you will not like the results.
Till next time.
09-18-2009 7:47 AM