'Error CS0246: The type or namespace name 'NPOI' could not be found (are you missing a using directive or an assembly reference?)

I'm setting up a DevOps pipeline and during the build, I keep running into the error:

ScreeningController.cs(19,7): Error CS0246: The type or namespace name 'NPOI' could not be found (are you missing a using directive or an assembly reference?)

I cannot figure out why the error is appearing. I checked my .csproj an packages.config files for the solution and NPOI is already included. If I build on Visual Studio on my local machine it builds fine. But on the pipeline it's causing the issue.

This is my NuGet task configuration:

enter image description here

I'm very new to DevOps and ASP .NET applications so sorry if I missed something obvious.



Solution 1:[1]

This can be the result of a .Net framework version incompatibility between two projects.

It can happen in two ways:

  1. a client profile project referencing a full framework project; or
  2. an older framework version targeting a newer framework version For example it will happen when an application is set to target the .Net 4 Client Profile framework, and the project it references targets the full .Net 4 framework.

So to make that clearer:

  • Project A targets the Client Profile framework
  • Project A references Project B
  • Project B targets the full framework The solution in this case is to either upgrade the framework target of the application (Project A), or downgrade the target of referenced assembly (Project B). It is okay for a full framework app to reference/consume a client profile framework assembly, but not the other way round (client profile cannot reference full framework targeted assembly).

Note that you can also get this error when you create a new project in VS2012 or VS2013 (which uses .Net 4.5 as the default framework) and:

  • the referencing project(s) use .Net 4.0 (this is common when you have migrated from VS2010 to VS2012 or VS2013 and you then add a new project)

  • the referenced projects use a greater version i.e. 4.5.1 or 4.5.3 (you've re-targeted your existing projects to the latest version, but VS still creates new projects targeting v4.5, and you then reference those older projects from the new project)

For more information, you can refer to Compiler Error CS0246.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kangcheng Jin-MSFT