Unit Test Adapter threw exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

The other day I came across this problem that I had not seen before. It was to do with running unit tests in Visual Studio 2008. All tests would fail with the exception:

Unit Test Adapter threw exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
The strange thing is that the tests would pass when run with debugging on.

It turned out that it was because the target assembly was signed, we had Code Coverage on, AND we did not specify a key for Code Coverage to re-sign with. Code Coverage is disabled in debugging – hence the problem only occurs when running without debugging!

It appears that Code Coverage needs to modify the assembly being tested. If the target assembly is signed, it will need to remove the key token, and re-sign it after it’s done. If you have Code Coverage on for multiple assemblies in the solution, then they will be all be re-signed with the same key. This means that your projects in the solution should be signed with the same key.

Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in Unit Test. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s