nunit3-vs-adapter: Adapter 3.8.0 breaks when tests uses newer Mono.Cecil

After updating to 3.8.0, I had a test project that disappeared from Test Explorer in Visual Studio. If I tried to use dotnet test to run the tests, I’d see that NUnit “failed to load” the assembly and that “No test is available”.

I’ve been able to reduce the problem down to a simple repro project, which I’ve attached to the issue.

The test assembly is referencing Mono.Cecil 0.10.0-beta6, with a simple test that uses one of its types. If I use 3.8.0-alpha1 of the adapter, the test is discovered properly, and the test passes. If I instead use 3.8.0, the test is still discovered, but when I run it, it fails with the following error:

Message: System.IO.FileLoadException : Could not load file or assembly 'Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

While still using 3.8.0, if I then add an additional package that uses Mono.Cecil more extensively, PublicApiGenerator 6.1.0-beta2, the test no longer appears in the Test Explorer window at all, and I can’t run the test from the command line with dotnet test.

Using this package with 3.8.0-alpha1, everything works correctly, The test is discovered and passes.

TestAdapterProblem.zip

Versions:

  • NUnit 3.7.1
  • NUnit3TestAdapter 3.8.0
  • VS 2017 Professional 15.2 26430.16 (also tested on 15.3.0 Preview 4 with .NET Core 2.0 Preview 2.0 installed)
  • .NET Framework 4.5.2 - 4.7 (didn’t try anything earlier)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 45 (29 by maintainers)

Most upvoted comments

Good news: I fixed this and added nupkg acceptance tests proving that it works! https://github.com/nunit/nunit3-vs-adapter/pull/541

I’ve finished the work of completely removing Mono.Cecil from the VS test adapter (though not the shared NUnit engine published by the nunit-console repo). I’m expecting that the next release will contain this change.

(https://github.com/nunit/nunit3-vs-adapter/issues/296#issuecomment-365499002)

What happens if you run your tests targeting .NET Framework 4.5+ using the NUnit Console instead of dotnet test? Same error? This might be more appropriate as an NUnit Engine issue rather than an adapter issue.

Using the TestAdapterProblem repro I included here, if I’m using 3.8.0 of the test adapter, I get the following when I use the console runner:

1) Error : TestAdapterProblem.Test.TestMethod
System.IO.FileLoadException : Could not load file or assembly 'Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at TestAdapterProblem.Test.TestMethod()

If I use the alpha, then everything works correctly and the test passes.