How come classes in subfolders in my App_Code folder are not being found correctly?

后端 未结 6 1482
野性不改
野性不改 2020-12-15 00:47

I am getting 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 fou

相关标签:
6条回答
  • 2020-12-15 01:03

    Check for BuildAction property of file. This should be set to "Compile"

    0 讨论(0)
  • 2020-12-15 01:06

    As you add folders to your app_code, they are getting separated by different namespaces, if I recall correctly, using the default namespace as the root, then adding for each folder.

    0 讨论(0)
  • 2020-12-15 01:10

    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>
    
    0 讨论(0)
  • 2020-12-15 01:11

    It might not be the correct way but I find it the easiest.

    Create the class in the main Folder as usual, then move it with your mouse to your sub-folder. Re-compile and all should be fine.

    0 讨论(0)
  • 2020-12-15 01:21

    In Visual Studio (2010 at least, but I recall past versions too), you can right click on the folder, within Solution Explorer, and then choose "Include in Project".

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

    This worked for me.

    0 讨论(0)
  • 2020-12-15 01:28

    Is it possible that you haven't set the folder as an application in IIS (or your web server)? If not, then the App_Code that gets used is that from the parent folder (or the next application upwards).

    Ensure that the folder is marked as an application, and uses the correct version of ASP.NET.

    0 讨论(0)
提交回复
热议问题