A place for spare thoughts


Troubleshooting: Resharper, Visual Studio 2010, MSTest and .NET 3.5 in single bottle

Filed under: Unit testing, VisualStudio — Ivan Danilov @ 15:59

We are in process of moving .NET 3.5 project to .NET 4.0 and VS2010. We’re still not ready to move our app to .NET 4.0 but decided to adopt VS2010 first. It is somewhat unusual situation so it caused some troubles.

First of all, unit testing projects under MSTest just can’t target framework v3.5 prior to VS2010 SP1.

VS2008 for unit testing was using Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly, version It was for v3.5 so everything is cool. Except the fact that if VS2010 sees version in any reference to this assembly – it starts Project Conversion Dialog and prompts you to convert your solution. Thus in VS2010 you just can’t have reference to (nevertheless MSBuild works well with it, so it seems it is VS limitation).

VS2010 (without SP1) switched to with the same name. Well, to be precise file version is 10.0.30319.1. If your unit testing project references – it can’t have TargetFrameworkVersion=v3.5. VS just sets it back to v4.0. So if you need to test v3.5 assemblies with it – well, you’re in trouble.

Fortunately, MS recognized the problem before I faced it and with SP1 there’s new version of the assembly – or 10.0.40219.1. It allows you to target v3.5 framework and test in the VS2010. After I realized it and changed my references to – native VS test runner get test correctly. Everything was green and bright.

Just until I ran it in the ReSharper 5.1 which I had installed. Well, it had test count correctly but don’t run anything. After some stack overflow searching I ensured that I’m not only one with the problem and that it is fixed in ReSharper 6.0. So I installed 6.0, run tests and… half of them were broken! Something is not right. Native runner got them well.

After some debugging I find out in Debug -> Windows -> Modules that resharper’s runner had 10.0.30319.1 version loaded. Maybe it is the problem was my first thought. Well, how could I force program to load other version of the assembly in .NET? With configuration, namely with assembly binding redirection. I had just happened to see MS guide to troubleshoot VS2010 unit testing. So my problem seemed very close…

So, I had opened my c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config and added there such lines:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.UnitTestFramework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="" newVersion=""/>
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="" newVersion=""/>
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="" newVersion=""/>
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Tip" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="" newVersion=""/>

After that ReSharper gets my tests correctly.

To be honest I don’t understand why this redirection actually solved the problem. We are telling runtime to load instead of in case it is requested, not vice-versa. But it is analogous to config file in many MS applications like devenv.exe.config, mstest.exe.config etc, so probably they know what to do with their own libraries better than I do.


1 Comment »

  1. […] from source machine’s GAC. Notice that some of these assemblies have two versions if you have VS2010 SP1 installed: and You need them both. Do not rename assembly […]

    Pingback by MSTest 2010 on the build server without VS2010 installed « A place for spare thoughts — 12/07/2011 @ 23:25

RSS feed for comments on this post. TrackBack URI

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: