22

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.

ASutherland
  • 77
  • 1
  • 8
Bunnynut
  • 1,156
  • 5
  • 14
  • 37

4 Answers4

26

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/

Rob Prouse
  • 22,161
  • 4
  • 69
  • 89
  • Nice, thank you. How come this is a problem when there is no explicit reference to that specific .dll? – Bunnynut Jan 31 '18 at 08:55
  • 2
    The VSTest system tries to load the engine, but fails to find it since the cache is corrupt. This is happening outside your project, so it is a not a reference issue. Also, feel free to delete the whole cache folder, it will recreate itself anyway: c:\users\username\appdata\local\temp\VIsualStudioTestExplorerExtensions. If one of these are corrupt, it's likely the others are corrupt too. – Terje Sandstrøm Jan 31 '18 at 11:42
  • 3
    In my case I only have `3.9.0` folder, instead of `NUnit3TestAdapter.3.9.0`. However, after deletion is also worked fine. – Nenad Feb 01 '18 at 08:42
  • 8
    No VisualStudioTestExplorerExtensions folder VS2019 16.7.3 – Vlado Pandžić Oct 07 '20 at 15:09
  • 1
    Nor in VS 2022 17.1.3. According to https://github.com/nunit/nunit3-vs-adapter/issues/261#issuecomment-478240651, "The VisualStudioTestExplorerExtensions folder issue has been fixed in later VS versions, so that is why you don't see this anymore." – Ian Kemp Apr 11 '22 at 17:06
1

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.

Boltyk
  • 317
  • 3
  • 10
  • 1
    This is for the devs using Visual Studio and Nuget for NUnit: There are often many different Nuget libs in a solution, such as for example NUnit, NUnit.Consolerunner, NUnit.Extension.NUnitProjectLoader, NUnit.Extension.TeamCityEventListener and NUnitTestAdapter3. This depends of course upon your usage of NUnit. Go to the Solution node in Solution Explorer in Visual Studio for example and go to Manage Nuget Packages. Then look at Consolidate, for version conflicts. – Tore Aurstad Apr 24 '21 at 19:52
1

I had a slightly different fix being that I did not have that folder in my Temp directory. I had to downgrade the version of nUnit using NuGet, build and recompile, before subsequently updating to the latest version again.

-1

Seems in project file you have mentioned reference of 3.7.0 as GAC, and that dll is not available in GAC which is hopefully causing the failure.

Mr. N. Das
  • 61
  • 8