15
votes

I'm currently working in the Visual Studio 2012 RC with a test project. I have included the following assemblies:

  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.SmoExtend
  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Management.Sdk.Sfc

These assemblies are build in version 2.0.50727 and I have a test project in .NET 4.0. So based on this information I have added an app.config file into the project with the following lines:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

When I'm going to run this I receive all the time the following message:

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

Is this a bug in a Visual Studio 2012 RC Test Project that it ignore's the app.config file or am I doing something completely wrong?

For additional information I have included also my test code:

    var connectionString = new SqlConnectionStringBuilder()
    {
        DataSource = @"(local)",
        IntegratedSecurity = true
    }.ConnectionString;

    var sql = "alter database [Test] set single_user with rollback immediate go ";
    sql += "drop database [Test] go ";
    sql += "create database [Test] go ";
    sql += Properties.Resources.Test;

    var connection = new SqlConnection(connectionString);
    var server = new Server(new ServerConnection(connection));

    server.ConnectionContext.ExecuteNonQuery(sql);
2
It can't just be "app.config", it must match the name of the program that executes the code and be stored in the same directory as that exe. Which is the test runner. I'm guessing at C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.x86.exe.config. Beware that this file already exists. Painful. - Hans Passant
Ah, so that's why I couldn't make it work. I'll try your suggestion Hans and will report back here. - Michiel Peeters
Hello Hans, it worked! You are absolutely right about it, only now I need to find something out how I can make this possible for other developers, but that doesn't matter now. Thanks again! - Michiel Peeters
@HansPassant you should put this as an answer and get it accepted :) - Not loved
@MichielPeeters how did you spread this to the other developers? Or did you find another way to solve the issue? - kalasp

2 Answers

1
votes

This seems to be fixed in Visual Studio 2012 when it went RTM. No need to update config files

I've tested that in Visual Studio 2012 Update 4 and Visual Studio 2013 Update 1 RC and your code works flawlessly with the above mentioned code and assembly references and without updating the config file of the test runner. It is possible this was broken in a beta or release candidate of Visual Studio 2012, but if it was, it seems to be fixed now.

As Hans mentions you can update the .config file for the vstest.executionengine.x86.exe.config, but that changes the behavior for all test projects on your machine and needs to be applied to all people working on your project (and on a build server should you be using one). This should be a last resort!!

0
votes

Check to make sure you don't have an older version of .Net 4.0 installed. If you downloaded either the 2010 VS beta or the 2012 VS beta, that can happen and then for some reason it will spool up the wrong one. Oh, and it would be a side-by-side install with the current .Net 4.0 . reference