CS0234:类型或命名空间名称 '<namespace2>' 在命名空间 '<namespace1>' 中不存在(是否缺少程序集引用?)

6
我有一个项目收到了"The type or namespace '' does not exist in the class or namespace ''" 错误。我看到这里有很多解决方案,但我还没有能够解决我的问题。
我有一个解决方案包含2个项目: Web.Frameworks.Database和Web.Reports.OrderReporting。我试图在Reports.OrderReporting中引用Frameworks.Database项目。我已经确认这两个项目都编译到相同的框架(.NET Framework 4.5)。更新:我已经在解决方案资源管理器中添加了对该项目的引用。
此时,Frameworks.Database项目中只有一个.cs文件,文件内容不多,如下所示:
using System;
using System.Data;
using System.Web;
using System.Data.SqlClient;


namespace Web.Frameworks.Database
{
    public class AccessDB : IHttpModule
    {
        /// <summary>
        /// You will need to configure this module in the Web.config file of your
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpModule Members

        public void Dispose()
        {
            //clean-up code here.
        }

        public void Init(HttpApplication context)
        {
            // Below is an example of how you can handle LogRequest event and provide 
            // custom logging implementation for it
            context.LogRequest += new EventHandler(OnLogRequest);
        }



        public void OnLogRequest(Object source, EventArgs e)
        {
            //custom logging logic can go here
        }

        #endregion

        public string ConnectionString;

        public string DumbLittleMethod()
        {
            return "This is my oh so fancy string.";
        }...

如果我通过调试器运行这段代码(在Visual Studio中按F5),一切都正常。但是如果我构建我的解决方案,然后通过Internet Explorer访问该页面,那么我就会在第11行出现错误。

Line 9:  using System.Data;

Line 10: using System.Data.SqlClient;

Line 11: using Web.Frameworks.Database;

Line 12: 

欢迎提供任何建议或技巧。我已经花了很多时间阅读类似的问题,但是很不幸没有成功。谢谢!


有时您可能需要手动向项目添加引用。只需在解决方案资源管理器下,右键单击您的项目,然后单击“添加引用”。一个窗口将打开,在 .Net 选项卡下搜索您的命名空间并添加它。我希望这可以解决问题。 - Khan
谢谢,Khan,我已经做过了(但是在我的原始问题中忘记提到了)。 - Karen
1个回答

4
我已经解决了这个问题。 实际问题是我的IIS虚拟目录没有指向正确的文件夹,所以页面找不到dll(这些dll在我的项目中已经正确引用)。
我之前遇到过一个“解析器错误消息:无法加载类型”错误,在这行代码上:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Orders.aspx.cs" Inherits="Web.Reports.OrderReports.Orders" %>

但是我曾经认为通过将 "CodeBehind" 更改为 "CodeFile"(在另一个关于解析器错误消息的线程中推荐)来解决该问题。不幸的是,这是一个误导性的提示,因为这只会使代码在运行时而不是编译时编译。

最终,我通过在全新的解决方案/项目中创建一个小的“Hello World”页面来解决了这个问题。再次遇到解析器错误,然后通过正确修复我的虚拟目录来解决它,之后我就可以引用dll和其他项目了。

感谢那些查看并发表评论的人-我感激你们的时间。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接