Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Could not load file or assembly 'nunit.engine, Version=3.7.0.0

Tags:

I have a webappliction with a separate test-project using NUnit to run unittests. When my test-project is trying to discover tests I run into the following exception:

An exception occurred while test discoverer 'NUnit3TestDiscoverer' was loading tests. Exception: Could not load file or assembly 'nunit.engine, Version=3.7.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb' or one of its dependencies. The system cannot find the file specified.

This is of course a very common error, but I can't find a reference to this particular assembly anywhere or what other dependency is actually causing the issue. Another thing is that I currently have 3.9.0 installed of NUnit instead of the mentioned 3.7.0. I have already tried cleaning and rebuilding the solution and restored all Nuget packages and clearing the obj directory didn't help either.

like image 280
Bunnynut Avatar asked Jan 30 '18 16:01

Bunnynut


People also ask

Does NUnit work with .NET 5?

NUnit Console cannot run tests with TargetFramework "net5.

What is NUnit 3 test adapter?

The NUnit 3 Test Adapter allows you to run NUnit 3 tests inside Visual Studio. This is a new adapter, based partly on the code of the original NUnit Test Adapter, but modified to work with NUnit 3. It is not possible to run NUnit 2. x tests using this adapter.


2 Answers

This is happening quite frequently with the latest versions of Visual Studio. We are not sure why, but the cause is an incomplete copy of the test adapter in the Visual Studio cache. The fix is to delete the cached copy and restart Visual Studio.

The folder you want to delete is C:\Users\username\AppData\Local\Temp\VisualStudioTestExplorerExtensions\NUnit3TestAdapter.3.x.x depending on your username and the version.

See https://github.com/nunit/nunit3-vs-adapter/issues/261 and http://hermit.no/how-to-resolve-cases-of-visual-studio-no-tests-appearing/

like image 106
Rob Prouse Avatar answered Sep 20 '22 23:09

Rob Prouse


In my case it was

An exception occurred while invoking executor 'executor://nunit3testexecutor/': Could not load file or assembly 'nunit.engine, Version=3.9.0.0

And the problem is: in my test project I have an import of NUnit3TestAdapter.3.13.0

  <Import Project="..\..\..\packages\NUnit3TestAdapter.3.13.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\..\packages\NUnit3TestAdapter.3.13.0\build\net35\NUnit3TestAdapter.props')" />

And in another project I have NUnit.Engine.3.10.0 referenced. but NUnit3TestAdapter.3.13.0 has Nunit.Engine.3.9.0 in the package.

\packages\NUnit3TestAdapter.3.13.0\build\net35

So, the solution was to downgrade Nunit.Engine in another project to 3.9 version.

like image 27
Boltyk Avatar answered Sep 17 '22 23:09

Boltyk