Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 Test Project Mixed Mode Runtime

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);
like image 930
Michiel Peeters Avatar asked Aug 15 '12 14:08

Michiel Peeters


People also ask

How to enable unmanaged debugging in Visual Studio?

Select the C++ project in Solution Explorer and click the Properties icon, press Alt+Enter, or right-click and choose Properties. In the <Project> Property Pages dialog box, expand Configuration Properties, and then select Debugging. Set Debugger Type to Mixed or Auto. Select OK.

How do I open a Webtest file in Visual Studio?

Open Visual Studio. On the start window, choose Create a new project. On the Create a new project page, type web test into the search box, and then select the Web Performance and Load Test Project [Deprecated] template for C#.

How to enable debugging in Visual Studio?

In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.


1 Answers

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!!

like image 112
jessehouwing Avatar answered Oct 19 '22 05:10

jessehouwing