Visual Studio 要求我引用一个不存在的程序集 [英] Visual Studio asks me to reference a nonexistent assembly

查看:29
本文介绍了Visual Studio 要求我引用一个不存在的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以某种方式使我的项目处于 Visual Studio 2013 无法编译它并出现荒谬错误的状态:

I somehow brought my project to a state where Visual Studio 2013 fails to compile it with a ridiculous error:

类型System.Collections.Generic.Dictionary`2"是在未引用的程序集中定义的.您必须添加对程序集System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"的引用.

The type 'System.Collections.Generic.Dictionary`2' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

首先,没有这样的程序集,它不存在.其次,Dictionary定义在mscorlib.dll中,当然默认引用.Resharper(有自己的代码分析引擎)报告解决方案应该可以正常编译.

First of all, there is no such assembly, it does not exist. Second, Dictionary<TKey, TValue> is defined in mscorlib.dll, which is referenced by default, of course. Resharper (which has its own code analysis engine) reports that the solution should compile normally.

我不知道这到底是怎么发生的,因为我最近的更改与所谓的错误地点完全无关.该行引用了一些标准的 LINQ 函数(GroupByToDictionary),并且它在没有任何更改的情况下运行了 几个月.不幸的是,我无法创建任何 MRE:显然,这个错误只出现在我的巨大解决方案的上下文中,并且仅在可能不相关的地方进行了一些特定的更改.

I don't know how on Earth it could happen, because my latest changes have nothing to do with the supposedly erroneous place at all. The line references some standard LINQ functions (GroupBy and ToDictionary), and it worked for months without any changes. Unfortunately, I cannot create any MREs: obviously, this error only appears in the context of my huge solution, and only with some specific changes made in the presumably irrelevant places.

这是我尝试过的,但没有奏效:

Here's what I tried, and it didn't work:

  • 清理 + 重建
  • 将目标框架从 .NET 4.5 更改为 .NET 4.5.1 或 .NET 4.0

有没有人见过这样的怪癖?

Has anyone seen such a quirk before?

推荐答案

检查项目中的所有(核心 .net)引用是否有效,并且它们都引用相同的 .NET 框架版本.

Check that all the (core .net) references in your project are valid and they all reference the same .NET framework version.

如果有疑问,请删除所有引用并重新添加(使用 4.0.0.0)版本.

If in doubt, remove all references and add them again (using the 4.0.0.0) versions.

我曾经遇到过这种情况(有完全相同的错误),这是由于参考版本的某些搞砸".我从来没有弄清楚为什么会发生这种情况,但是删除所有引用并再次添加它们对我有用.

I had this happen to me once (with the exact same error) and it was due to some "screw up" on the version of the references. I never got to find out WHY it happened, but removing all references and adding them again worked for me.

这篇关于Visual Studio 要求我引用一个不存在的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆