Nunit — the type or namespace cannot be found

Steve Ellwood
2 min readNov 24, 2020

--

This was an issue that randomly cropped up one day in a number of my libraries. This sort of error is quite a common one and there can be a number of solutions, in this case my normal routine didn’t work, nor did reinstalling Nunit.

As I use Paket I then tried an older version in case it was that which was causing the issue. Fortunately in Paket this is a ridiculously simple process — just add version <old.version.number> to your paket.dependencies file but that made no difference either.

By sheer luck I decided to try a different library and that one worked! Comparing the tests project files showed a number of differences, the working one was pretty minimal

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1; net471</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>

The ones that didn’t work tended to have more fields completed but taking those out made no apparent difference, then I noticed the tfm’s. The ones that weren’t working all have netcoreapp2.1 as well as those above. Simply removing that resolved the issue.

I’m sure it will come as no suprise to many of you that it turned out that the issue was of course one of my own making. Shortly before it started I had added framework restrictions to my paket.dependencies file

// limit frameworks
framework: netstandard2.0, netcoreapp3.1, net471
...

I had incorrectly assumed that netstandard 2.0 would cover netcoreapp2.1. When I explicitly added netcoreapp2.1 to the above it worked as expected.

--

--

Steve Ellwood

Senior Integrations Officer at Doncaster Council Any views expressed are entirely my own.