[nunit-discuss] NUnit 2.5.4 and .NET 4

228 views
Skip to first unread message

Alan

unread,
Apr 20, 2010, 9:02:45 AM4/20/10
to NUnit-Discuss
Hello All!

While trying to get a test suite running under .NET 4 with NUnit 2.5.4
I ran into a few hurdles, and figured it might be helpful for me to
share them and how I got past them here.

So on my first run of a .NET 4 assmebly, I just ran:

nunit-console.exe TestAssembly.dll

like I always have. The result was a BadImageFormat exception. I
noticed that the runtime was 2.0, so I thought maybe passing /
framework would clean things up. When I ran /framework, though, I
received the following exception:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance
of an obj
ect.

Server stack trace:
at NUnit.Util.ProcessRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Util.RemoteTestAgent.AgentRunner.Load(TestPackage package)
at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(
IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInCont
ext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(R
untimeMethodHandle md, Object[] args, Object server, Int32 methodPtr,
Boolean fE
xecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
req
Msg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgDa
ta, Int32 type)
at NUnit.Core.TestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Util.ProcessRunner.Load(TestPackage package)
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
at NUnit.ConsoleRunner.Runner.Main(String[] args)

That was no good, so I started digging deeper. Tons of folks mentioned
that they had to change the nunit-console.exe.config file, but I
figured that wouldn't be required anymore since the site said there
was 4.0 support. But, after this last exception I thought it was worth
a try, so I tweaked the config file, adding:

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

to the top of the configuration section. I saved and ran ncover-
console, but without the /framework flag, thinking I wouldn't need it,
and I got the following exception:

Unhandled Exception:
System.ArgumentException: The net-4.0 framework is not available
Parameter name: framework
at NUnit.Util.TestAgency.GetAgent(RuntimeFramework framework, Int32
waitTime,
Boolean enableDebug)
at NUnit.Util.ProcessRunner.Load(TestPackage package)
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
at NUnit.ConsoleRunner.Runner.Main(String[] args)

I know I have .NET 4 installed, so I assumed that net-4.0 referred to
something similar to the net-2.0 folder in the bin folder of NUnit.
Things were starting to feel a bit hopeless. But, as one last ditch
effort, I added the /framework flag back, and:

ProcessModel: Default DomainUsage: Single
Execution Runtime: v4.0.30319
...........
Tests run: 11, Errors: 0, Failures: 0, Inconclusive: 0, Time:
3.8432198 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

Tada! It worked. So, in conclusion, for me to run with .NET 4 I had to
tweak the appropriate .exe.config file and run with the /
framework=4.0.30319 flag. Mileage may vary, but that's what worked for
me.

Alan

--
You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
To post to this group, send email to nunit-...@googlegroups.com.
To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.

Charlie Poole

unread,
Apr 20, 2010, 11:02:33 AM4/20/10
to nunit-...@googlegroups.com
Hi Alan,

Thanks for the recap and workaround info. Yes, the best way to use
NUnit 2.5.4 on a system
that has .NET 4.0 Final (or RC) is to run nunit under that runtime. It
will still be able to run
tests under .NET 2.0, 1.1, etc. if you tell need to run older work -
and should do so automatically.

This is not, however, how NUnit is intended to work in this release.
It _should_ run under any
runtime >= 2.0 and automatically find all runtimes that you have
installed. Unfortunately, the
object that launches tests in a separate process is hard-coded to look
for .NET 4.0 beta 1
or beta 2, and this slipped through into the release. It's a bit
confusing, because other parts of
NUnit do recognize your release. For example, it's listed in the File
menu, but if you select
it the process is still not lauched correctly.

The fix for this will be in the 2.5.5 release this week.

Charlie

Alan

unread,
Apr 20, 2010, 10:53:12 PM4/20/10
to NUnit-Discuss
That's great to hear. Thanks for getting back in touch.

On Apr 20, 11:02 am, Charlie Poole <nunit...@gmail.com> wrote:

> The fix for this will be in the 2.5.5 release this week.

Alan

unread,
Apr 23, 2010, 9:50:48 AM4/23/10
to NUnit-Discuss
I just tested NUnit 2.5.5, and I'm excited to say that I didn't have
to tweak the app's config file. Simply running NUnit with /
framework=net-4.0 did the trick. Running without /framework=net-4.0
causes the same System.BadImageFormatException to occur, but that
makes sense since it's running in the .NET 2 CLR. Is there any plan to
make that exception more user friendly? We've had several users get in
touch with us at NCover because they think that NCover's breaking
things for them because they're upgrading their whole testing stack at
once.

Charlie Poole

unread,
Apr 23, 2010, 10:50:01 AM4/23/10
to nunit-...@googlegroups.com
Hi Alan,

Bad news! I'd like to fix this quickly and re-upload if we can figure it out.

NUnit is probably running under .NET 2.0, which it should do on a system
that has that version installed. It should detect that your test assembly
is built with .NET 4.0 and run it under 4.0 in a separate process without
the need for any other settings to be specified.

This problem might occur if you are overriding the default and forcing the
test to run in the same process. This could be by use of a command-line
option for the console runner or through the general NUnit settings for
either runner. However, I would not expect this option to be fixed by
specifying the /framework option.

Can you provide some details as to just how you are executing, what
settings are in any project file and what your general settings are with
respect to use of processes?

Charlie

Alan

unread,
Apr 26, 2010, 9:56:40 AM4/26/10
to NUnit-Discuss
Charlie,

I'm just running a really basic command line to get the error:

"C:\Program Files\NUnit 2.5.5\bin\net-2.0\nunit-console.exe"
TestProject.dll

No project files or other settings. Here's my full output:
http://gist.github.com/379362

Let me know what additional info you need.

Alan

Charlie Poole

unread,
Apr 26, 2010, 11:59:01 PM4/26/10
to nunit-...@googlegroups.com
Yes, I am able to reproduce this behavior in the console runner only.
I'll look for the cause
tomorrow. Can you file a bug for it please?

Charlie

Alan

unread,
Apr 28, 2010, 9:59:09 AM4/28/10
to NUnit-Discuss

Charlie Poole

unread,
Apr 28, 2010, 10:58:03 AM4/28/10
to nunit-...@googlegroups.com
Thanks! The code will be in the repository later today, for those who want it.

Charlie
Reply all
Reply to author
Forward
0 new messages