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...
Status: VERIFIED INVALID
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]
URL:
Depends on:
Blocks:
 
Reported: 2016-04-14 16:16 UTC by Peter Collins
Modified: 2016-05-19 10:20 UTC (History)
3 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED INVALID

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 ###
https://bugzilla.xamarin.com/attachment.cgi?id=14855

### 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.2.6.4.20150512/nunit-console.exe 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 4.2.2.30 (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