Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharpSVN and C# Problem

When trying to add SharpSVN to my C# project, compiling with SharpSVN related calls gives me this error:

FileLoadException was Unhandled 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.

What I did was add the References from the downloaded SharpSVN zip file and added the

using SharpSvn;

When I compile that it works fine, but when I add:

string targetPath = "https://bobl/svn/ConsoleApplication1";

SvnTarget target;
SvnTarget.TryParse(targetPath, out target);

It breaks with that error. I've searched this error and have had no luck in finding a solution.

like image 600
Sam F Avatar asked Jun 08 '10 17:06

Sam F


3 Answers

Add this to your app.config if you want to keep targeting .NET 4:

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

This will enable the loading support of mixed mode assemblies (mostly C++/CLI assemblies containing both unmanaged and managed code) built for an older version of the framework.

like image 199
Julien Lebosquain Avatar answered Nov 05 '22 01:11

Julien Lebosquain


The SharpSVN assembly is a mixed assembly built against version 2.0 of the CLR.
Therefore, it cannot be loaded in CLR version 4.0.

You need to change your project to target .Net 3.5 (or earlier) in Project Properties.
Since .Net 2.0, .Net 3.0, and .Net 3.5 all use version 2.0 of the CLR, it will work in any of those versions.

like image 6
SLaks Avatar answered Nov 05 '22 00:11

SLaks


As Julien mentioned you need to add the compatibility code to your project's app.config or web.config:

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

This is all well and good, but if you are having this problem with a test runner (like MSTest) inside Visual Studio, you actually have to make this change to the test runner's config file.

I wrote a post about this very problem in VS 2012:

http://www.diaryofaninja.com/blog/2012/09/13/net-20-mixed-mode-assemblies-in-visual-studio-net-45-test-projects

In Visual Studio 2012, you need to add the startup code to the following file:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine86.exe.config
like image 1
Doug Avatar answered Nov 05 '22 00:11

Doug