How-to: Unable to cast object Microsoft VisualStudio TestTools UnitTesting TestConfiguration

I was getting this error when running one of my unit tests:

Unit Test Adapter threw exception: The type initializer for ‘Microsoft.VisualStudio.TestTools.UnitTesting.TestConfiguration’ threw an exception.
Unable to cast object of type ‘Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection’ to type ‘Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection’.

The issue was due to a versioning problem in the .config file (I upgraded to VS 2008).  The section that you’ll want to change is Version=8.0.0.0 to Version=9.0.0.0:

<section name=”microsoft.visualstudio.testtools” type=”Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=…”/>

Hope this helps.

Leave a Reply

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