SharpSVN and C# Problem
Asked Answered
H

3

9

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.

Haydon answered 8/6, 2010 at 17:40 Comment(0)
B
6

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.

Bladdernut answered 8/6, 2010 at 17:42 Comment(5)
Or obtain a version of SharpSVN built with .NET 4.0.Tillich
Did the trick, thanks. Is it unsafe to use an old version of .Net?Haydon
@Sam F, No there are CLR changes, that's why!Magnesia
There is nothing wrong with targeting .Net 3.5. (Except that you won't be able to use classes that are new to .Net 4.0)Bladdernut
Or apply the configuration change that is documented in the actual error message.Flaxseed
H
31

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.

Hauptmann answered 8/6, 2010 at 17:46 Comment(0)
B
6

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.

Bladdernut answered 8/6, 2010 at 17:42 Comment(5)
Or obtain a version of SharpSVN built with .NET 4.0.Tillich
Did the trick, thanks. Is it unsafe to use an old version of .Net?Haydon
@Sam F, No there are CLR changes, that's why!Magnesia
There is nothing wrong with targeting .Net 3.5. (Except that you won't be able to use classes that are new to .Net 4.0)Bladdernut
Or apply the configuration change that is documented in the actual error message.Flaxseed
N
1

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
Nena answered 13/9, 2012 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.