Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio mistakes valid code as invalid after debug edit

I am using visual studio 2013 with unity 3.5 downloaded using nuget. I have Container class that looks like the following

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

    //continuation here
  }

My problem is when I execute the application, debug runs fine, but if I edited a statement completely unrelated to the class above during debug process, when I resume debugging I get the following strange error with blue underline below _container!!

enter image description here

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'

after this I will have to stop debug and restart again. without touching anything the error disappears and can debug back.

I looked for System.Runtime assembly in Framework assemblies but I could not find it. the available assemblies are:

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

any way how to at least track down this error?

like image 405
IdontCareAboutReputationPoints Avatar asked Jan 21 '26 16:01

IdontCareAboutReputationPoints


2 Answers

Finally I found the solution.

There is a system.runtime.dll in %ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\ I added a reference to it and it solved the problem. I don't know if this the right thing to do but at least the IDisposable error disappeared. I wonder why this assembly is not listed in standard assemblies list.

like image 173
IdontCareAboutReputationPoints Avatar answered Jan 23 '26 08:01

IdontCareAboutReputationPoints


I was experiencing this same problem (though I didn't need to edit while debugging to trigger it). For me, it turned out that the (false) error messages were actually being generated by Resharper rather than Visual Studio. I was able to confirm this by doing Tools | Options | Resharper | Suspend Now; all the little red squiggles instantly went away. With that clue in hand, I was able to discover 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.

like image 39
dlf Avatar answered Jan 23 '26 06:01

dlf