Code4IT

The place for .NET enthusiasts, Azure lovers, and backend developers

Type or namespace not found: how to fix Error CS0246 in .NET Core

2019-08-26 2 min read Blog
Just a second! 🫷
If you are here, it means that you are a software developer. So, you know that storage, networking, and domain management have a cost .

If you want to support this blog, please ensure that you have disabled the adblocker for this site. I configured Google AdSense to show as few ADS as possible - I don't want to bother you with lots of ads, but I still need to add some to pay for the resources for my site.

Thank you for your understanding.
- Davide

Something strange happened today.

I’ve 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.

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.

.NET version selection on Visual Studio 2019

So, the lesson is: know your enemy and check for the slight details.

This article first appeared on Code4IT

ABOUT THE AUTHOR

Davide Bellone is a software developer with more than 10 years of professional experience with Microsoft platforms and frameworks.

He loves learning new things and sharing these learnings with others: that’s why he writes on this blog and is involved as speaker at tech conferences.

He's a Microsoft MVP 🏆 and content creator on LinkedIn🔗.