In my previous post I linked to a lab on the unity interception extension. I have used a similar solution in one of my current projects. In this project we use TFS and a build server with automatic builds. All unit tests passed when I run them locally, but they failed on the build server. I received the following error message.
System.TypeInitializationException: The type initializer for ‘xxxContainer’ threw an exception. —> System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for unity: Value cannot be null.
When I examined the out directory on the build server, I noticed that the file Microsoft.Practices.Unity.Interception.Configuration.dll was missing. It seems like the build server just copies instrumented dll´s to the out directory. I do not explicitly use anything from this assembly in my code, so it wasn’t copied. The types are loaded dynamically during runtime. I added a piece of dummy code that used a type in the assembly, and then the assembly was copied to the out directory and all unit tests passed on the build server. There must be a better way to solve this…