Visual studio 在调试编辑后将有效代码误认为无效

Visual studio mistakes valid code as invalid after debug edit

我正在使用 visual studio 2013 和使用 nuget 下载的 unity 3.5。我的容器 class 如下所示

  public class Container
  {
    static IUnityContainer _container; //<- System IDisposable error on _container
    static ILogger _logger = GetLogger();

    //continuation here
  }

我的问题是当我执行应用程序时,调试运行正常,但是如果我在调试过程中编辑了一个与上面的 class 完全无关的语句,当我恢复调试时我会得到以下蓝色的奇怪错误下面划线 _container!!

The type 'System.IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

之后我将不得不停止调试并重新启动。无需触摸任何东西,错误就会消失并且可以调试回来。

我在框架程序集中寻找 System.Runtime 程序集,但找不到。可用的程序集是:

System.Runtime.caching System.Runtime.DurableInstancing System.Runtime.Remoting System.Runtime.Serialization System.Runtime.Serialization.Formatters.Soap

有什么办法至少可以找到这个错误吗?

终于找到解决方法了

%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\中有一个system.runtime.dll,我添加了一个对它的引用,它解决了问题。我不知道这样做是否正确,但至少 IDisposable 错误消失了。 我想知道为什么这个程序集没有列在标准程序集列表中。

我遇到了同样的问题(虽然我不需要在调试时编辑来触发它)。对我来说,事实证明(错误的)错误消息实际上是由 Resharper 而不是 Visual Studio 生成的。我可以通过 Tools | Options | Resharper | Suspend Now; 来确认这一点;所有的红色小波浪线立即消失了。有了这条线索,我发现了 this ticket; which shows this is a known issue with Resharper 9.0. The fix will be included in version 9.2, which appears to be scheduled for August. If you're impatient like me, you can get the fix now by installing the latest EAP (early access preview) from this location.