Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does visual studio give me Type is not defined for my App_Code classes?

"Type 'HR.Database' is not defined'

I get that error for several classes that are stored in the App_Code folder in the Error List panel when building my project.

It is a class I wrote with namespace HR

How can I reference it or alter the project to recognize those classes and remove the error?

I thought I should reference it but when trying to add a reference there are no items in the list of projects. Also, they are .vb files and not a .dll

like image 906
masteroleary Avatar asked Dec 02 '22 19:12

masteroleary


1 Answers

I wasted the better part of a working day on this problem before figuring it out...

When you add files to App_Code, Visual Studio sets the "Build Action" property to "Content", instead of "Compile" which it does for all other classes. So your classes don't get compiled, and then VS complains that it can't find them. Presumably this is VS' way of saying that App_Code is not where you should put your app code, reasonable as it may appear.

The solution is to right-click on each file and reset "build action" to "compile". This also has to be done whenever you add files. Or you could submit to VS and put your source somwhere else.

< /frustration>

like image 69
jforberg Avatar answered Dec 22 '22 09:12

jforberg