Tim
Tim

Reputation: 7421

unable to evaluate expression whilst debugging

When debugging asp.net code (running against IIS, and using Visual studio 2013) and in a breakpoint and trying to evaluate a variable using quick watch i quite often get "unable to evaluate expression".

deleting the .suo from the asp.net project folder seems to resolve the issue (After reloading the solution)

Is this a recognised bug? getting this a lot now in Visual studio 2013 on more than one machine.

Upvotes: 57

Views: 74946

Answers (5)

Shubh
Shubh

Reputation: 6741

I faced it today with VS2013.

Goto Tools --> Options --> Debugging --> General --> Scroll to the bottom for "Use Managed Compatibility Mode" and Select the option.

Screenshot from the blog(url below): enter image description here Restart you debugging.

What Helped Me is below!

Upvotes: 96

Simon_Weaver
Simon_Weaver

Reputation: 145920

Some of these options change over time - and top rated solutions in other answers don't seem to all exist any more - searching the options dialog can help.

Right now for a ASPNET Core project I found this, and enabling it seems to be helping:

enter image description here

Suppress JIT optimization on module load (Managed only): Disables the JIT optimization of managed code when a module is loaded and JIT is compiled while the debugger is attached. Disabling optimization may make it easier to debug some problems, although at the expense of performance. If you are using Just My Code, suppressing JIT optimization can cause non-user code to appear as user code ("My Code"). For more information, see JIT optimization and debugging.

If it doesn't seem to help I'd suggest turning it off again.

Upvotes: 8

Aftab Ahmed
Aftab Ahmed

Reputation: 885

Go to Tools --> Options --> Environment --> General --> check "Automatically adjust visual experience based on client performance" option.

Upvotes: -4

sudhansu63
sudhansu63

Reputation: 6180

I have faced this for specific project and the reason is Costura.Fody (embeds all DLLs into the executing assembly).

In this case you can disable Costura.Fody.

  1. Comment out Costura from FodyWever.xml

    <Weavers>
      <!--<Costura />-->
    </Weavers>
    
  2. Disable the clean reference target (if included) in *.csproj

    <!--<Target Name="CleanReferenceCopyLocalPaths" AfterTargets="AfterBuild">
        <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%
         (DestinationSubDirectory)%(Filename)%(Extension)')" />
        <Exec Command="DeleteEmptyDirectory.bat" />
      </Target>-->
    

Upvotes: 0

JaredPar
JaredPar

Reputation: 754615

The C# debugging engine relies heavily on the CLR debugger in order to evaluate expressions. That message indicates that the CLR is in a state in which it is unable to perform simple evaluations and the reasons for that can include the following

  • a local variable is optimized away
  • the thread is stopped in a GC unsafe point
  • a previous function call caused the debugger to get into a bad state and hence further evaluations simply aren't possible

Upvotes: 8

Related Questions