Bug 40406 - Getting an InvalidCastException when running simple unit test project from command line via 'mono nunit-console.exe'
Summary: Getting an InvalidCastException when running simple unit test project from co...
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: 4.4.0 (C7)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: (C7)
Assignee: Alexander Köplinger [MSFT]
Depends on:
Reported: 2016-04-14 16:16 UTC by Peter Collins
Modified: 2016-05-19 10:20 UTC (History)
3 users (show)

See Also:
Tags: c7regression
Is this bug a regression?: ---
Last known good build:


Description Peter Collins 2016-04-14 16:16:51 UTC
This is somewhat similar to Bug #38331 (and uses the same test case), but since it's not the same error I decided to file a new issue.

Attempting to build and run the following attachment with mono 4.4 throws an exception. However this same test case runs without issue against mono 4.2.3. This is a regression in the 4.4. branch.

### Test Case ###

### Steps ###
1. Download and unzip the attachment
2. Restore NuGet packages and build the project.
3. Use the nunit-console.exe in /packages/ to attempt to run the project.
>    mono SomeConsoleTest/packages/NUnit.Runners.lite. SomeConsoleTest/bin/Debug/SomeConsoleTest.dll

### Output ###
> Execution Runtime: mono-4.0
> Unhandled Exception:
> System.InvalidCastException: Specified cast is not valid.
> Server stack trace: 
>   at (wrapper xdomain-dispatch) NUnit.Core.RemoteTestRunner:Load (object,byte[]&,byte[]&)

> Exception rethrown at [0]: 

>  at (wrapper xdomain-invoke) NUnit.Core.RemoteTestRunner:Load (NUnit.Core.TestPackage)
>  at NUnit.Util.TestDomain.Load (NUnit.Core.TestPackage package) <0x28fcc98 + 0x00262> in <filename unknown>:0 

### Environment ###
Mono 4.4.0 (mono-4.4.0-branch/3fc068f) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Package version: 404000129
Mac OS X 10.11.1
Comment 1 Alexander Köplinger [MSFT] 2016-04-14 17:49:08 UTC
I can repro even on master. Running with mono --debug=casts says "System.InvalidCastException: Unable to cast object of type 'NUnit.Core.TestPackage' to type 'NUnit.Core.TestPackage'".
Comment 2 Alexander Köplinger [MSFT] 2016-04-18 17:20:36 UTC
Update: If I remove everything except SomeConsoleTest.dll, SomeConsoleTest.dll.mdb and nunit.framework.dll from bin/Debug then it works fine.

This suggests to me it's some sort of assembly mismatch between the version that NUnit.Runners.lite brings in and the one from the NUnit nuget.

Actually, I don't see why the runner adds references to the library project at all, the runner should be separate from the actual unit test assembly. The official NUnit.Runners 2.6.4 package for example doesn't have this issue since it doesn't add any references to the unit test assembly itself.
Comment 3 Alexander Köplinger [MSFT] 2016-04-18 17:31:04 UTC
More importantly, I see the exact same behavior on Mono (C6) too. It crashes with InvalidCastException but works when removing the bogus nunit files. Looks like this isn't a bug/regression.
Comment 4 Saurabh 2016-05-19 10:20:50 UTC
I am also getting this issue (System.InvalidCastException: Specified cast is not valid). If I delete all nunit files except nunit.framework.dll then I am not seeingthis exception. This is the output: https://gist.github.com/saurabh360/ca8db19ae666badbb695f053f2447809

Note You need to log in before you can comment on or make changes to this bug.