views:

204

answers:

4

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.

+3  A: 

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.

SLaks
Or obtain a version of SharpSVN built with .NET 4.0.
David Lively
Did the trick, thanks. Is it unsafe to use an old version of .Net?
Sam F
@Sam F, No there are CLR changes, that's why!
Srinivas Reddy Thatiparthy
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)
SLaks
+2  A: 

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.

Julien Lebosquain
A: 

Agreed with Julien's solution - this fixed it for me.

CJBrew
A: 

Slaks answer it's right, but I prefer Julien way

xandy