【问题标题】:VS2015: The type 'XXX' is defined in an assembly that is not referencedVS2015:类型“XXX”在未引用的程序集中定义
【发布时间】:2015-12-27 19:03:44
【问题描述】:

我有一个刚刚移植到 VS2015 的 Web 表单项目。

在母版页上,我有以下设置响应消息的公共方法:

public void SetResponse(string responseMessage, Utilities.ResponseType cssClass)
{
    ResponseToUser.Text = !String.IsNullOrWhiteSpace(responseMessage) ? Utilities.GetResponse(responseMessage, cssClass) : "";
}

在 Utilities.cs 文件中,我有枚举和 GetResponse:

namespace WEB
{
    public class Utilities
    {
        public enum ResponseType
        {
            Success,
            Info,
            Warning,
            Danger
        }

        public static string GetResponse(string message, ResponseType response)
        {
            return "<div id=\"response\" class=\"alert alert-" + response.ToString().ToLower() +
               " fade in\"><a href=\"#\" class=\"close\" data-dismiss=\"alert\">&times;</a>" + message + "</div>";
        }
    }
}

在子页面中,我调用母版页上的公共方法,如下所示:

if (Request.QueryString["msg"] == "changepassword")
    Master.SetResponse("Please change your password before continuing", Utilities.ResponseType.Warning);

VS2015 将Master.SetResponse 显示为错误,说:

CS0012 The type 'Utilities.ResponseType' is defined in an assembly that is not referenced. You must add a reference to assembly 'App_Code.pay9mvri, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

在子页面的顶部,我有对 Utilities 命名空间的引用:

using WEB;

所以ResponseType 枚举位于引用的命名空间中。为什么将其突出显示为错误?该网站仍然可以正常构建和运行,但我想摆脱所有错误消息。这在 VS2013 中不是问题 - 完全相同的项目。

【问题讨论】:

  • 能否在代码示例中添加程序集名称、命名空间和类名称?
  • 您必须添加对程序集“App_Code.pay9mvri”的引用 - 您是否尝试过清除 .NET Framework 缓存并重新启动机器?似乎它有一个旧版本卡在临时文件中
  • @RGraham 这就是我所怀疑的,我尝试重建但没有运气,而且它也发生在项目/解决方案中。重新启动PC也无济于事。还有什么想法吗?
  • 嗯,我看过这里 - 其中一些答案可能适用 - stackoverflow.com/questions/496269/…
  • @Herdo 我不确定你需要哪些名字,我想我已经包含了所有相关的名字。

标签: c# .net webforms visual-studio-2015


【解决方案1】:

我重新安装了最新版本的 VS,似乎解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-17
    • 2016-10-01
    • 2011-08-16
    • 2014-08-15
    • 2016-05-01
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多