views:

6205

answers:

6

I'm trying to load a Visual Studio 2010 beta dll into the NUnit GUI. I get a popup error.

This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. You may be attempting to load an assembly build with a later version of the CLR than the version under which NUnit is currently running.

How do I force an executable to run under .NET 4?

+52  A: 

I've downloaded the NUnit 2.5 source and opened the VS2008 solution in the VS2010 beta. Once the conversion finished I opened all the projects and changed the target framework setting for all the projects to ".NET Framework 4.0". I then built the solution without any errors. I can now use the NUnit GUI app to run tests built for .NET 4.0. I've not done exhaustive testing of this build so there may be problems, but for my purposes it works fine.

Update: It is not necessary to rebuild NUnit. I discovered that if you add the following to the relevant NUnit config file you can run a test dll built for .NET 4.0.

Under <configuration> add:

<startup>
  <requiredRuntime version="v4.0.20506" />
</startup>

and under <runtime> add:

<loadFromRemoteSources enabled="true" />
Charles Cook
Worked like a charm. Thanks!
Ball
Ok, the configuration updates make it work, but I had to use version="v4.0.21006" for my requiredRuntime tag.
mkmurray
Beautiful! Worked perfectly. Thanks.
scottmarlowe
BTW, the default location of the config file is:C:\Program Files\NUnit 2.5.3\bin\net-2.0\nunit.exe.configAdding those options to the config worked for me.
Brad Irby
This worked for me when using the consolerunner as well. I was running using the NUnit task for MSBuild Community Tasks project.
Mark Struzinski
Couldn't get this to work with the latest Nunit + .net4 RTM. I added the suggested entries to nunit-console.exe.config but I get: System.ArgumentException: The net-4.0 framework is not availableTried with the above versions + v4.0.30319I'm running 2008 R2 x64
Andreas
For the console runner, change the configs as mentioned, but using v4.0.30319 for the RTM version of .NET 4.0. Also, run it with this command line argument: /framework=4.0.30319
Lance Fisher
I had luck using the command line option /framework:net-4.0.30319 instead of changing the config. This was helpful so I could control which applications used the 4.0 CLR and which did not.
Kevin Crowell
A: 

You have to rebuild NUnit with the latest version of the clr:

NUnit for NET 4.0

justin.m.chase
NUnit 2.5.3 has .NET 4 support according to the release notes
Sander Rijken
I saw that release note as well, but I still get the original poster's error message as well. I have not yet tried the config file changes. I will report back.
mkmurray
Ok, the configuration updates make it work, but I had to use version="v4.0.21006" for my requiredRuntime tag.
mkmurray
+2  A: 

The proposed solution worked great for getting NUnit to run. Unfortunately, when I then got to my code coverage step, NCover started giving me:

Profiled process terminated. Profiler connection not established.

The best solution I found to this was to just use the "-x86" version of NUnit with NCover:

NCover.Console.exe nunit-console-x86.exe --additional params--

Works now.

scottmarlowe
Thank you for this, I was experiencing the same issue, your fix solved it!
CubanX
+8  A: 

With .NET 4 being released, I used

<supportedRuntime version="v4.0.30319" />

in the NUnit 2.5.4 exe.config instead of requiredRuntime, and the loadFromRemoteResources tag as shown above and all worked well. Thanks!

pelazem
BINGO BINGO! +1!
John Gietzen
+5  A: 

In NUnit 2.5.5 you can specify in the command line the option /framework=net-4.0 and it is compatible with the new assemblies generated with the release of the latest VS2010.

Cristian
I have never been able to get this to work. I have seen people use /framework:net-4.0.30319 and all sorts of other variations. Would be nice if they included the actual options on the site docs.
Jason Short
This option, as mentioned in the post, works for me. Thanks!
Bas Jansen
@Jason It appears that this only works on the console version. The GUI version doesn't have this option.
romkyns
A: 

If you experience this issue after upgrading to nunit 2.5.5 then you will need to upgrade nant to the latest version for me it was .91 alpha.

Adam