Why are classes in subfolders in my App_Code folder not found correctly?

I get the following error when I put class files in subfolders of my App_Code folder:

errorCS0246: The type or namespace name "MyClassName" could not be found (did you specify a usage directive or assembly reference?)

This class is not in the namespace at all. Any ideas?

+7
c # namespaces app-code
source share
6 answers

You need to add codeSubDirectories to your compilation element in web.config

<configuration> <system.web> <compilation> <codeSubDirectories> <add directoryName="View"/> </codeSubDirectories> </compilation> </system.web> </configuration> 
+18
source share

Check the BuildAction property of the file. To do this, install "Compile"

+16
source share

Is it possible that you did not set the folder as an application in IIS (or on your web server)? If not, then App_Code is used, this is from the parent folder (or the next application up).

Make sure the folder is marked as an application and is using the correct version of ASP.NET.

+1
source share

This may not be entirely correct, but I think this is the easiest.

Create a class in the main folder, as usual, then move it with the mouse to your subfolder. Re-compile and everything should be in order.

+1
source share

When you add folders to your app_code, they become separated by different namespaces, if I remember correctly, using the default namespace as the root, and then adding for each folder.

0
source share

In Visual Studio (at least 2010, but I also remember past versions), you can right-click on a folder in Solution Explorer and select "Include in Project".

Then, on the properties tab for each file (or select them all at once), you select Compile for the Create Action property.

It worked for me.

0
source share

All Articles