Home Blog .NET The type or namespace name 'xxx' could not be found (are you missing a using directive or an assembly reference?) after adding the class in the same namespace
The type or namespace name 'xxx' could not be found (are you missing a using directive or an assembly reference?) after adding the class in the same namespace
.NET
Written by Dicky   
Friday, 03 June 2011 12:06
AddThis Social Bookmark Button

I stumble upon this error whenever I create a new class. For some reason, when I try to instantiate the object, it just won't recognize the class that I just created despite defining the class in the same namespace. I spent about an hour trying to figure it out, it will work if I define the class in the same file or if I put I create it in a root folder.

Turns out, the culprit is with the App_Code folder, whenever I created a new Class file, it will set the "Build Action" in Properties for the particular class file to "Content" instead of "Compile". All you need to do is to rename the App_Code folder to something else and change the Build Action to compile, then when you create a new class file from that folder, it will set the Build Action properly to Compile.

Note that simply moving the class file from the App_Code folder to other folder will not change the Build Action property. I hope this can help other people figuring out what is wrong with their code. Trust me, this issue is almost driving me crazy and make me feel so stupid trying to figure this out despite of having years of programming experience and using Visual Studio as my main IDE. You definitely learn something new everyday!