如何解决“找不到类型或命名空间”的问题 编译错误?
我担心我所付费的网络托管配置不正确。 在我的本地计算机上正确编译和运行的 ASP.NET 网站一旦部署就无法工作。
我正在处理的问题是编译错误:CS0246,“找不到类型或命名空间(您是否缺少“using”指令或程序集引用?)
我的网站包含以下文件和文件夹:
websitedemo/Default.aspx
websitedemo/Default.aspx.cs
websitedemo/App_Code/HelloClass.cs
发生编译错误如果我尝试使用我的应用程序代码文件夹中包含的任何代码。 如果有助于解决错误,我已将整个 /websitedemo/ 文件夹包含在此存档中: http:// kivin.ca/websitedemo/source.zip
我已将该文件夹保留为调试模式。 编译错误屏幕可以在http://kivin.ca/websitedemo/查看。
祝好。
-- 更新:
如果它有助于解决此错误,我就得到了当我尝试部署 ASP.NET WebApplication 而不是网站时发生的行为。
如果我的 aspx 文件直接包含 @Page,如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="myproj._Default" Debug ="true" %>
我得到的编译错误是:“解析器错误消息:无法加载类型“myproj._Default”。”
正在使用 Build -> 通过 ftp 部署 Web 应用程序 发布-> [X] 替换匹配的文件,[X] 仅运行此应用程序所需的文件。 [X] 包含 App_Data 文件夹。
I'm concerned that the web hosting that I'm paying for is not configured correctly. ASP.NET Web Sites which compile and run correctly on my local machine don't work once they're deployed.
The issue I'm dealing with is a compilation error: CS0246, "Type or namespace could not be found (Are you missing a 'using' directive or assembly reference?)
My Web Site contains the following files and folders:
websitedemo/Default.aspx
websitedemo/Default.aspx.cs
websitedemo/App_Code/HelloClass.cs
The compilation error occurs if I attempt to use any code contained in my App Code folder.
I've included the entire /websitedemo/ folder in this archive if it helps troubleshoot the error: http://kivin.ca/websitedemo/source.zip
I've left the folder in debug mode. The compilation error screen may be viewed at http://kivin.ca/websitedemo/
Best regards.
-- update:
If it helps troubleshoot this error, I've got the behaviour that occurs when I attempt to deploy an ASP.NET WebApplication instead of Website.
In the case that my aspx file includes a @Page direct like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="myproj._Default" Debug="true" %>
The compilation error I get is: 'Parser Error Message: Could not load type 'myproj._Default'.'
The webapps are being deployed via ftp using Build -> Publish -> [X] Replace matching files, [X] Only files needed to run this app. [X] Include App_Data folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我要感谢大家的支持。 这是最值得赞赏的。 我已经与我的网络托管公司的专家联系,他们告诉我这不是代码或服务器配置错误,而只是我的控制面板中遗漏了一个步骤。
将我的网站工作目录设置为虚拟目录解决了该问题。
感谢 stack Overflow 社区和 Softsys Hosting 的杰出支持人员。
I'd like to thank everyone for their support. It's most appreciated. I've been in contact with a specialist at my web hosting company and they've advised me that this isn't a code or server configuration error, but just a missed step in my control panel.
Setting my website working directory as a virtual dir resolved the issue.
Thanks to the stack overflow community and the outstanding support people at Softsys Hosting.
如果您在本地构建站点并将生成的 dll(将包含 HelloClass)上传到 bin 目录,我打赌它会起作用。
If you build your site locally and upload the resulting dll (that will contain HelloClass) to the bin directory, I bet it will work.
尝试将 HelloClass.cs 放入命名空间中,并将“Using”放在默认文件的顶部
Try putting your HelloClass.cs in a namespace and put Using at the top of your default file
http://msdn.microsoft.com/en-us/library/54dwfbb7。 aspx
我认为这可能对你有帮助...如果你
也有子文件夹,app_code是在framework 2.0中引入的,你能检查一下live box上的Web应用程序是否设置为使用framework 2.0? 否则类不会在那里编译
http://msdn.microsoft.com/en-us/library/54dwfbb7.aspx
i think this may help you... if you have subfolders
also, app_code was introduced in framework 2.0, can you check that the web application on the live box is set to use framework 2.0 ? otherwise the classes wont get compiled in there