【问题标题】:CS0234: The type or namespace name '<namespace2>' does not exist in the namespace '<namespace1>.' (are you missing an assembly reference?)CS0234: 命名空间“<namespace1>”中不存在类型或命名空间名称“<namespace2>”。 (您是否缺少程序集参考?)
【发布时间】:2014-03-28 08:57:13
【问题描述】:

我有一个项目收到“类或命名空间''中不存在类型或命名空间'”错误。我在这里看到了很多解决方案,但我无法解决我的问题。

我有一个包含 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 选项卡下打开一个窗口,搜索您的命名空间并添加它。我希望这能解决问题。
  • 谢谢,汗,我已经这样做了(但在我原来的问题中没有提及)。

标签: c# .net namespaces .net-assembly


【解决方案1】:

我已经解决了这个问题。

真正的问题是我在 IIS 中的虚拟目录没有指向正确的文件夹,所以页面找不到 dll(在我的项目中正确引用)。

我之前在这一行遇到了"Parser Error Message: Could not load type" 错误:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Orders.aspx.cs" Inherits="Web.Reports.OrderReports.Orders" %>

但我认为我已经通过将“CodeBehind”更改为“CodeFile”解决了这个问题(正如另一个站点上关于解析器错误消息的另一个线程中所建议的那样)。不幸的是,这是一个误导性的提示,因为这只会使代码在运行时而不是编译时编译。

我终于解决了这个问题,在一个带有“Hello World”页面的全新解决方案/项目中重新开始,再次遇到解析器错误,一旦我正确修复它(通过修复我的虚拟目录),我就可以引用 dll 和其他项目。

感谢观看和评论的人 - 感谢您的宝贵时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2020-12-17
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多