App_Code 文件夹问题
因此,我正在设计的新网站上的 App_Code 文件夹遇到了一个非常奇怪的问题。
我在 App_Code 文件夹的命名空间内有一个基本类。 当我设置命名空间并从类中创建一个对象时,IDE 中的一切工作正常。 它会在鼠标悬停时显示类摘要,当您单击“转到定义”时,它会转到类文件。 而且在本地也运行得很好。
但是,当我将该网站加载到服务器上时,访问该页面时收到此错误消息:
第 10 行:使用 System.Web.UI.WebControls;
第 11 行:使用 System.Web.UI.WebControls.WebParts;
第 12 行:使用 xxxx.xxxx
编译器错误消息: CS0246:找不到类型或命名空间名称“xxxxxx”(是否缺少 using 指令或程序集引用?)
我知道类文件就在那里。 有人知道发生了什么事吗?
编辑:
约翰,是的,这是一个 2.0 网站。
So I'm having a really weird issue with my App_Code folder on a new website I'm designing.
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.
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
Compiler Error Message: CS0246: The type or namespace name 'xxxxxx' could not be found (are you missing a using directive or an assembly reference?)
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的类未编译的问题,您只需转到 App_Code 文件夹中任何类的属性并将其“Build Action”属性从“Content”更改为“Compile”即可解决此问题
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"
我注意到,每当引用的程序集或代码文件中发生编译时错误时,IDE 解析器和编译器之间有时会出现不匹配。 在这种情况下,IDE 将正确识别类型并为它们提供全面支持,但由于编译器无法创建引用的对象,因此它会抱怨引用的对象不存在。
现在我不想指责任何人——这只是一个猜测——但您应该确保引用的代码文件中没有任何错误。
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.
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.
根据您发布站点的方式,它不会在 App_Code 中查找,而是在包含该类的 Bin 文件夹中查找 DLL。 你是如何将你的网站转移到服务器上的?
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 中命名了一个类“HTML”。 花了很长时间才弄清楚这只是一个名称冲突,因为编译器并没有非常有帮助地告诉我问题是什么。
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 (和 App_Data)没有放在服务器的根目录中,而是放在包含其他所有内容的子文件夹中。 一定要扎根!
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!
如果您的应用程序是 Web 应用程序项目而不是网站项目,则代码文件不应该位于 App_Code 文件夹中(我知道这是愚蠢的设计)。 创建一个名为 code 或其他名称的新文件夹并将它们放入其中。
当我将一堆旧的 .Net 网站升级为应用程序项目时,它给我带来了各种各样的问题。
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.
It caused me all sorts of problems when I upgraded a bunch of old .Net web sites to application projects.