I write about .NET development and general coding stuff. - developer - blogger - speaker -
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.
But I was close: the Class Library was in .NET Framework 4.7.2 but the application was in .NET Framework 4.7.1. It 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
Create your free account to unlock your custom reading experience.