I have create a new empty web application in c# Asp.net 4.0 and then added App_Code
folder then added 3 classes into that folder. I have added a web user control and set the reference of App_Code
class into the control but it throws an error.
The type or namespace name 'App_Code' does not exist in the namespace (are you missing an assembly reference?)
Any ideas?
This point can be confusing.
A "web application project" is not expecting the App_Code
folder.
A "website project" would expect that folder and know how to use it.
Whether you realize it or not (and depending upon which version of Visual Studio you use), you will get a WAP or a WSP when you first create your web solution. They are different. It takes some effort to convert from one to the other.
Here are a few articles explaining the differences.
To solve your immediate problem, then, you can just move the 3 class files out of the App_Code
folder into the root folder, or better, create a new folder to contain those classes and move them into it. Depending upon whether you give the classes in that folder namespaces, you may have to add a reference to that namespace in your UserControl
.