C# App_Code 文件夹问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/89570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
App_Code folder issues
提问by Ethan Gunderson
So I'm having a really weird issue with my App_Code folder on a new website I'm designing.
所以我在我设计的一个新网站上的 App_Code 文件夹遇到了一个非常奇怪的问题。
I have a basic class inside of a namespace in the App_Code folder. Everything works fine in the IDE when I setup the namespace and make an object from the class. It brings up the class summary on hover, and when you click on "go to deffinition" it goes to the class file. And it also works fine localy.
我在 App_Code 文件夹中的命名空间中有一个基本类。当我设置命名空间并从类中创建对象时,IDE 中的一切正常。它会在悬停时显示类摘要,当您单击“转到定义”时,它会转到类文件。它在本地也能正常工作。
However, when I load the site onto my server, I get this error message when I access that page:
但是,当我将站点加载到我的服务器上时,我在访问该页面时收到此错误消息:
Line 10: using System.Web.UI.WebControls;
Line 11: using System.Web.UI.WebControls.WebParts;
Line 12: using xxxx.xxxx
第 10 行:使用 System.Web.UI.WebControls;
第 11 行:使用 System.Web.UI.WebControls.WebParts;
第 12 行:使用 xxxx.xxxx
Compiler Error Message:CS0246: The type or namespace name 'xxxxxx' could not be found (are you missing a using directive or an assembly reference?)
编译器错误消息:CS0246 :找不到类型或命名空间名称“xxxxxx”(您是否缺少 using 指令或程序集引用?)
I know for a fact that the class file is there. Anyone have any idea of whats going on?
我知道类文件就在那里。任何人都知道发生了什么?
Edits:
编辑:
John, yes it is a 2.0 site.
约翰,是的,这是一个 2.0 站点。
回答by X-Cubed
If your application is a Web Application project rather than a Web Site project, the code files should not be in the App_Code folder (stupid design, I know). Create a new folder called code or something and put them in there.
如果您的应用程序是 Web 应用程序项目而不是网站项目,则代码文件不应位于 App_Code 文件夹中(愚蠢的设计,我知道)。创建一个名为 code 之类的新文件夹并将它们放在那里。
It caused me all sorts of problems when I upgraded a bunch of old .Net web sites to application projects.
当我将一堆旧的 .Net 网站升级到应用程序项目时,它给我带来了各种各样的问题。
回答by Jeffrey L Whitledge
I have noticed a mismatch sometimes between the IDE parser and the compiler whenever a compile-time error occurs in a referenced assembly or code file. In that circumstance the IDE will correctly identify the types and provide full support for them, but since the compiler was unable to create the referenced objects, it will complain that the referenced objects don't exist.
我注意到每当引用的程序集或代码文件中发生编译时错误时,IDE 解析器和编译器之间有时会不匹配。在这种情况下,IDE 将正确识别类型并为它们提供全面支持,但由于编译器无法创建引用的对象,它会抱怨引用的对象不存在。
Now I don't want to go accusing anybody of anything—this is just a guess—but you should probably make sure there are not any errors in your referenced code file.
现在我不想去指责任何人——这只是一个猜测——但你应该确保你引用的代码文件中没有任何错误。
回答by Danny Tuppeny
Depending on how you publish the site, it won't look in App_Code, it'll look for a DLL in the Bin folder that contains the class instead. How did you transfer your website to the server?
根据您发布站点的方式,它不会在 App_Code 中查找,而是会在包含该类的 Bin 文件夹中查找 DLL。你是如何将你的网站转移到服务器的?
回答by pirsqua
This just happened to me and the solution was that App_Code (and App_Data) were not put in the root of the server, but in a subfolder that held everything else. Must be in root!
这只是发生在我身上,解决方案是 App_Code(和 App_Data)没有放在服务器的根目录中,而是放在一个包含其他所有内容的子文件夹中。必须在root!
回答by Mazen Elkashef
The problem that your classes are not compiled, You'll solve this issue simply by going to the properties of any class in the App_Code folder and change it's 'Build Action' property from "Content" to "Compile"
您的类未编译的问题,您只需转到 App_Code 文件夹中任何类的属性并将其“构建操作”属性从“内容”更改为“编译”即可解决此问题
回答by krowe2
For those that follow...I had this same set of issues but it was caused because I named a class in App_Code, 'HTML'. Took a long while to figure out that it was just a name conflict because the compiler wasn't being very helpful about telling me what the problem was.
对于后面的人……我也遇到了同样的问题,但这是因为我在 App_Code 中将一个类命名为“HTML”。花了很长时间才发现这只是一个名称冲突,因为编译器在告诉我问题是什么方面没有太大帮助。