Proposed 2.6.3 release: ArgumentNullException in NUnit.Framework.AsyncInvocationRegion..cctor

Bug #1235891 reported by Stefan Bodewig
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
Critical
Charlie Poole

Bug Description

I've built and run the tests of XMLUnit's trunk against the proposed 2.6.3 release assembly, all tests pass with 2.6.2.

At least on Mono (2.10) on Linux I now see an ArgumentNullException - haven't tried any other environment.

The test's code is https://sourceforge.net/p/xmlunit/code/HEAD/tree/trunk/xmlunit/src/tests/net-constraints/ValidationConstraintsTest.cs

Error stack trace (copy pasting from an xterm):

   [nunit2] Test Case Failures:
   [nunit2] 1) net.sf.xmlunit.validation.ValidatorTest.ShouldThrowWhenValidatingInstanceAndSchemaIsInvalid : System.TypeInitializationException : An exception was thrown by the type initializer for NUnit.Framework.AsyncInvocationRegion
   [nunit2] ----> System.ArgumentNullException : Argument cannot be null.
   [nunit2] Parameter name: method
   [nunit2] at net.sf.xmlunit.validation.ValidatorTest.ShouldThrowWhenValidatingInstanceAndSchemaIsInvalid () [0x00000] in <filename unknown>:0
   [nunit2] --ArgumentNullException
   [nunit2] at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0
   [nunit2] at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0
   [nunit2] at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0
   [nunit2] at NUnit.Framework.AsyncInvocationRegion..cctor () [0x00000] in <filename unknown>:0

Revision history for this message
Stefan Bodewig (stefan-bodewig) wrote :

Oops, I just see I linked to the wrong testcase, the correct one is https://sourceforge.net/p/xmlunit/code/HEAD/tree/trunk/xmlunit/src/tests/net-core/validation/ValidatorTest.cs

It might be an issue with Assert.Throws and an anonymous test delegate - I don't think I have such a construct in any of my other tests.

Revision history for this message
Stefan Bodewig (stefan-bodewig) wrote :

Sorry for the repeated noise, I seem to have been right with my last comment. I'll attach a small testcase which leads to

stefanb@brick:/tmp$ mono NUnit-2.6.3/bin/nunit-console.exe assertthrows.dll -basepath=NUnit-2.6.3/bin/
NUnit-Console version 2.6.3.13278 (Preview)
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Unix 3.5.0.41
  CLR Version: 2.0.50727.1433 ( Mono 3.5 ( 2.10.8.1 (Debian 2.10.8.1-5ubuntu1) ) )

ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-3.5
Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for NUnit.Framework.AsyncInvocationRegion at (wrapper xdomain-invoke) NUnit.Core.RemoteTestRunner:Load (NUnit.Core.TestPackage)
  at NUnit.Util.TestDomain.Load (NUnit.Core.TestPackage package) [0x00000] in <filename unknown>:0
Exception rethrown at [1]:
 ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: method
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0
  at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0
  at NUnit.Framework.AsyncInvocationRegion..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x00000] in <filename unknown>:0

Revision history for this message
Stefan Bodewig (stefan-bodewig) wrote :

I'm having a hard time building NUnit trunk on Mono 2.10 - this would be Mono 4.0 and things aren't quite where the build system expects them.

What happens is that the type constructor for AsyncInvocationRegion is triggered in line 579 of Assert - the framework assembly I use has been built for Windows - but in Mono the Exception class has no PreserveStackTrace method.

The branch I've just linked falls back to a no-op if the PreserveStackTrace isn't found at runtime.

TBH I'm not sure this is the best way to fix it - in particular since I don't have a Windows environment at hand right now - so I don't claim my trivial change would fix anything.

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 1235891] Re: Proposed 2.6.3 release: ArgumentNullException in NUnit.Framework.AsyncInvocationRegion..cctor

Yes, I did something similar as my first attempt, removing the static
constructor as well and adding a PreserveStackTrace method that uses
lazy initialization. The problem is twofold: (1) Mono doesn't have the
PerserveStackTrace method and (2) there's no reason to be messing
around with AsyncInvocationRegion in this example anyway, since no
async methods are involved.

The trouble is that IsAsyncOperation is a static method of
AsyncInvocationRegion and calling it triggers the static constructor.
Either that method has to be in another class or we need to do away
with all the static initialization. I did the latter.

I'm testing on Windows right now, by using the Gui runner to run the
NUnit tests under Mono. Before my fix, the tests would not even load.
With it they load but I'm getting some errors. I may need to move to a
Linux system to really get into this.

Charlie

On Sun, Oct 6, 2013 at 8:51 AM, Stefan Bodewig
<email address hidden> wrote:
> I'm having a hard time building NUnit trunk on Mono 2.10 - this would be
> Mono 4.0 and things aren't quite where the build system expects them.
>
> What happens is that the type constructor for AsyncInvocationRegion is
> triggered in line 579 of Assert - the framework assembly I use has been
> built for Windows - but in Mono the Exception class has no
> PreserveStackTrace method.
>
> The branch I've just linked falls back to a no-op if the
> PreserveStackTrace isn't found at runtime.
>
> TBH I'm not sure this is the best way to fix it - in particular since I
> don't have a Windows environment at hand right now - so I don't claim my
> trivial change would fix anything.
>
> --
> You received this bug notification because you are subscribed to NUnit
> Extended Testing Platform.
> https://bugs.launchpad.net/bugs/1235891
>
> Title:
> Proposed 2.6.3 release: ArgumentNullException in
> NUnit.Framework.AsyncInvocationRegion..cctor
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunitv2/+bug/1235891/+subscriptions

Changed in nunitv2:
importance: Undecided → Critical
status: New → Fix Committed
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.6.3
Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.