How to Fix Error CS0246: "Type or namespace not found" in .NET Core

Written by davidebellone | Published 2021/03/14
Tech Story Tags: dotnet | dotnet-core | error | net-core | .netcore | bug-fixing | fixing | bugs

TLDR The type or namespace name 'XX' could not be found (are you missing a using directive or an assembly reference?). The error was caused by the Class Library in.NET Framework 4.7.2 but the application was in the.NET Framework. It was the patch version of the patched version. The class library version is in the application in.NET. The error is: "Type or. namespace not found" in the Application Explorer or Alt+Enter in the Solution Explorer. You can find the version in the Properties screen of the project.via the TL;DR App

Have you encountered the type or namespace not found CS0246 error in .NET core? Well, so did! Here's how it happened to me and how I fixed it.
Something strange happened today.
I developed a Class Library in .NET Framework and I tested it with the related test library.
So I've integrated the library into another project. Everything was fine, I used that library without problems. But, all of a sudden:
Error CS0246: The type or namespace name 'XX' could not be found (are you missing a using directive or an assembly reference?).
What?!? I've been using it for the whole week. I've tested it. I've added the reference, and the Intellisense works as well.
C'mon, the class is here!
Clean the solution... nothing happens.
Close Visual Studio... still nothing.
Have a coffee... well, better now.
Suddenly, a doubt: what if I've created it in .NET Core instead of .NET Framework?
And, obviously... no, it wasn't that.

The Real Way to Fix the Namespace Not Found Error in .NET Core

But I was close: the Class Library was in .NET Framework 4.7.2 but the application was in .NET Framework 4.7.1It was the patch version!
So, I just downgraded the class library version through Visual Studio, and everything went well again.
How to Downgrade
You can find the version in the Properties screen of the project (right-click on the project in the Solution Explorer or Alt+Enter) in the Application tab, then under the Target framework field.
So, the lesson is: know your enemy, and check for slight details.

Written by davidebellone | I write about .NET development and general coding stuff. - developer - blogger - speaker -
Published by HackerNoon on 2021/03/14