98

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?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Ball
  • 2,591
  • 3
  • 19
  • 26

10 Answers10

132

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>
  <supportedRuntime version="v4.0.30319" />
</startup>

and under <runtime> add:

<loadFromRemoteSources enabled="true" />
Geoff Dalgas
  • 6,116
  • 6
  • 42
  • 58
Charles Cook
  • 1,989
  • 1
  • 16
  • 7
  • 3
    Ok, the configuration updates make it work, but I had to use version="v4.0.21006" for my requiredRuntime tag. – mkmurray Dec 24 '09 at 00:46
  • 4
    BTW, the default location of the config file is: C:\Program Files\NUnit 2.5.3\bin\net-2.0\nunit.exe.config Adding those options to the config worked for me. – Brad Irby Feb 16 '10 at 22:56
  • This worked for me when using the consolerunner as well. I was running using the NUnit task for MSBuild Community Tasks project. – Mark Struzinski Feb 25 '10 at 16:49
  • 2
    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 available Tried with the above versions + v4.0.30319 I'm running 2008 R2 x64 – Andreas Öhlund Apr 13 '10 at 21:48
  • 1
    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 Apr 20 '10 at 22:03
  • 1
    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 Jun 09 '10 at 23:20
  • +1 and updated the version no in the answer to the RTM version of .NET 4.0 as that is what people will be looking for now. – AdaTheDev Jan 19 '11 at 13:04
  • +1 Another data point: I made the two changes in the config file and now I can run .NET 4 tests in NUnit. :) – JeffH Oct 12 '11 at 15:37
  • +1 Surprisingly, pelazem's situation didn't work in one instance, but this fixed the GUI part of NUnit. – ashes999 Apr 26 '12 at 18:48
25

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
  • 1,352
  • 1
  • 11
  • 13
17

You don't have to modify any file

just open this file and everything will work just fine

C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-x86.exe

darky
  • 171
  • 1
  • 2
12

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 T
  • 2,245
  • 3
  • 25
  • 45
  • 3
    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 May 28 '10 at 22:49
  • 2
    @Jason It appears that this only works on the console version. The GUI version doesn't have this option. – Roman Starkov Aug 24 '10 at 21:14
  • +1 for mentioning that this works starting from version 2.5.5! I had NUnit throwing ArgumentExceptions and NullReferenceExceptions on one of my machines, and it turned out that it was because of version 2.5.0. – realMarkusSchmidt Dec 16 '11 at 12:28
2

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.

Scott Marlowe
  • 7,915
  • 10
  • 45
  • 51
2

To find your .net 4 version from the Visual [C# 2010 Express, or which ever] go to the Visual application's "About" under the menu's Help item. It should show up as the version under the Microsoft .NET Framework line on the top right hand side of the window.

Dan Paden
  • 21
  • 1
1

I ran into the very same error message while running NUnit 2.4.8. As I had not upgraded in some time I installed the current NUnit (v2.5.9) and found that it now supports VS2010 assemblies. So if you have newly encountered this error check your NUnit version: as of December 2010 (or so) the only thing you need to do is upgrade NUnit.

Michael Sorens
  • 35,361
  • 26
  • 116
  • 172
  • i am running NUnit 2.5.9 downloaded on 15/03/2011 and this problem just wont go away for me. Even if i try the proposed solution – DrLazer Mar 15 '11 at 17:29
1

As of NUnit 2.5.10 you can enable visual studio support in the GUI runner:

Tools-> Settings-> IDE Support

After that I was able to successfully attach to the nunit-agent.exe process which runs your assembly in a .NET 4.0 app domain

Crackerjack
  • 2,154
  • 3
  • 28
  • 36
0

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
  • 1
0

I found usefull to start from NUnit Application Template. It support VS C# Express, allows debugging tests and contains precompiled NUnit for .NET 4.0. Thank to author new test project gets ready with one click.

Ernest Poletaev
  • 558
  • 5
  • 15