paint-brush
How to Fix Error CS0246: "Type or namespace not found" in .NET Coreby@davidebellone
8,966 reads
8,966 reads

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

by Davide Bellone | Code4ITMarch 14th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

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.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How to Fix Error CS0246: "Type or namespace not found" in .NET Core
Davide Bellone | Code4IT HackerNoon profile picture

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.

Previously published at https://www.code4it.dev/blog/dotnet-type-or-namespace-not-found