Reputation: 27
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?
Upvotes: 0
Views: 306
Reputation: 572
Did you create the App_Code folder manually?
I was the impression the folder was created automaticaly when creating the project.
If not, when you add something to the project you select Add ASP folder, and it would have App_Code option along others there.
If the option isn't there is probably because you created a Web Application.
This might help you more: http://vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html
Upvotes: 0
Reputation: 32831
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
.
Upvotes: 2