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

可紊 提交于 2019-11-27 14:09:28

问题


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 found (are you missing a using directive or an assembly reference?)

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


回答1:


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>



回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/155105/how-come-classes-in-subfolders-in-my-app-code-folder-are-not-being-found-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!