Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality


:P
On this page:

Last week I ran into a really strange problem with an older WebForms application on Visual Studio 2013.  I was trying to debug my application on a breakpoint and when I hit the break point, none of the debugger member and watch expressions were working - specifically everything shows 'Could not evaluate expression' in the debugger. 

It appears that the issues discussed in this post have been addressed in Visual Studio 2013 Update 2, so updating to Update 2 (or later) might be the best path for avoiding the funky debugging behaviors described in this post. If you still have issues or simply can’t update to Update 2 yet, then the rest of this post is still relevant.

Here's what the error looks like for me:

DebuggingExpressionNotEvaluated

In this example, you can see a couple of scoped values in the debugger. Here both this and user are in scope and instantiated, but the debugger doesn't show the evaluated values/references for those objects to drill into. Instead I get the error icon and 'Could not evaluate expression'. In more complex code with more scoped variables, I basically see a wall of red icons - nothing at all is evaluated.

The Visual Studio 2013 Debugger introduces a new feature which allows evaluating the result value of functions. With this new feature the existing behavior of Property evaluation (which are essentially functions) has also changed and this new behavior is now the default. Unfortunately it looks like in this particular case it ended up causing a problem.

To be fair, I've been working on various different projects (there are about 15 projects that I use on a regular basis plus many test and 3rd party projects) and this one is the only one where I've run into this behavior, so this is most likely a very rare edge case (and I feel oh so lucky about that!).

As I've been in Redmond on the Microsoft Campus for the MVP Summit this week I pinged some of the VS debugger folks and they were kind enough to let me show them the issue in person today and together we poked around to try and figure out what's causing this problem.

Debug Breakpoint Corruption

First let me say that we managed to make the problem go away, although since we weren't able to repro the failure outside of my specific environment it's hard to say exactly what the problem is. But here is what it looks what ended up solving it.

The original project was a VS2012 project that was recently moved and opened in VS 2013 RTM. In the process of moving the project to VS 2013 it looks that the underlying Solution support file (the .suo) file got corrupted somehow. The solution file ended up containing a number of oddly duplicated breakpoints that looked something like this:

DupedBreakPoints

Notice the duplicated global.asax.cs debugger breakpoint entries that are nested below the main reference. There are a few more of these weird breakpoints in the project.

Also odd was that some of these breakpoints were dated and didn't actually show up in the IDE, and none of these breakpoints actually show up in the source code editor. For this reason I didn't originally notice these funky breakpoints, although I wondered about the phantom stops in Session_Start() when starting the project, but when we took a look at the failures we happened to notice the duplicated breakpoints.

This prompted me to delete the breakpoints and lo and behold, the problem went away. Yay. Problem solved.

Most likely however, the breakpoint issue is just a symptom that's causing a load failure on one or more of the .NET assemblies referenced by the Web project during startup. The phantom breakpoint in web.config most likely resulted in interrupted assembly loading, which in the course of debugging through the project startup appears to have been triggered in the debugger's assembly loader. It appears there might be a bug there, in that there's no proper recovery from an assembly load error that's going to be addressed in the future (looks like Microsoft is aware of this issue and has a patch in the works for it).

This likely accounts for the fact that we weren't able to duplicate the problem outside of my machine, even when copying off the project with the corrupted .suo file. It's likely a timing issue.

Other Fixes

The debugger folks were mentioning that this 'expression evaluation' problem has come up on a few occasions for developers, so there are other issues besides my odd corrupted breakpoints scenario. The thought is that any error during assembly loading can cause failure of the debugger to evaluate expressions later on in the debugging process.

Luckily there's a workaround should you run into this by using a flag in Tools | Options | Debugger | General , which allows you to disable the new function evaluation behavior and which essentially gives you the VS 2012 behavior:

TurnOffManagedCompatibilityMode

This also worked in eliminating the problem (I backed up the bad project to test for the failure), and if all fails this is an option that will get you going again. But you will get slightly different debugger behavior since when enabled you're actually getting a different debugger runtime. Still better than a non-working debugger :-)

The debugger folks mentioned they have a few bug fixes that will make it into the next Visual Studio update that are likely to solve these problems, so this is bound to be a temporary problem and a very edge case scenario at that. But when it does kick in, at least there is a workaround by reverting to the old behavior and make it work…

Posted in ASP.NET  Visual Studio  

The Voices of Reason


 

Martin
November 22, 2013

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Helped me alot, thank you!

Anup
November 26, 2013

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Many thanks for this. I kept getting this. Deleting the breakpoints and reattaching to debug again was all that was needed.

Knipjo
November 27, 2013

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Hi Rick,
Great tip. The issue I had was that my VS2K3 inside a Paralles Desktop virtual machine was not letting me debug step by step. You could step a couple of times, then it was frozen, then one more step, then it was frozen again. Not very practical. And it's doing that even with new solutions and any type of projects, console or WPF. Long story short, enabling that option makes everything work like a charm again. Thanks a lot for pointing that out.
John

Joe Capka
December 05, 2013

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Has a similar issue, but no breakpoints to delete. I ended up updating the sln file to use a newer version of VS (VisualStudioVersion = 12.0.21005.1) and build clean / rebuild. That seems to fix it too.

Dieter Wiesflecker
December 10, 2013

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

thanks, had the same problem, it occured just during woring in a Webservice, after enabeling managed Comp Mode it worked again!

Gage
January 07, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Thanks for the tip. I had the same problem migrating solutions from VS2010 and clearing all of the breakpoints fixed the problem.

Lotux
January 24, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Thansk a lot it was driving me mad :)

Jakub
January 25, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

This saved me, thanks!

John
February 07, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

I've encountered this problem often since upgrading to VS 2013. Thank you very much for the details on how to disable that new bit; I like VS 2013 but this debugger problem was a deal breaker for me and forced me to keep going back to VS 2012!

Ilia
March 10, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Had the same issue. Deleting breakpoints removed the problem. Thank you very much!!

Johan
March 18, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Thanks! Saved me a lot of head-scratching! :-)

David Madi
March 18, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Helped me a lot. Thanks.

Tim
March 25, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

All of my team have been experiencing the same issue. Cheers for that!

Claudio
March 26, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

It simply works like that!

Thanks a Lot!

Andrew Hall
March 31, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Regarding the bug with "Could not evaluate expression" bug; the fix for this was first included in Visual Studio 2013 Update 2 CTP 2 (http://www.microsoft.com/en-us/download/details.aspx?id=42023). Please try installing that. If that does not fix the issue, please let us know using the Visual Studio 2013 Feedback Tool (http://visualstudiogallery.msdn.microsoft.com/563d1003-f0ed-498f-8ef9-f8ee1aac39fe)

Thank you,
Andrew Hall
Visual Studio Debugger

Rob
April 04, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Andrew -

Typical Microsoft link you provided above -- already expired :(

Maria Ghiondea - MSFT
April 17, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

The link to the CTP2 has expired because the RC is now available: http://www.microsoft.com/en-us/download/details.aspx?id=42307

Thanks,
Maria Ghiondea
Visual Studio Debugger

Ben Jones
April 22, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Just ran into this very problem. Deleting old break points made no difference but using the compatibility debugger mode fixed the problem. I'll test VS 2013 update 2 soon. Thanks and see you on the beach! :)

kris
April 24, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

great, thanks for pointing out the "use managed compatiblity mode".

in my case another process loaded a copy (!) of the assembly i wanted to debug. i guess the problem was because vs saw multiple sources for the same assembly..? sure hope so :)

clau137
April 28, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

Just had the same problem and the compatibility flag fixed it. Could it be related to multi-threading? I hit the breakpoint from various threads and noticed the same type of list you showed for Global.asax.cs.

Rick Strahl
April 28, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

@clau137 - yes it probably is related to the multi-threaded stacks. But then an ASP.NET application is always multithreaded and requests always show up on random threads as they always have. The issue most likely is timing.

Guy Kroizman
June 01, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

There is an update from MS. http://stackoverflow.com/a/22642345/193016

Chan Pal
November 07, 2014

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

I am getting a compilation error, when compiling a project containing .pc (PRO *C) files, which is the same one you all faced during debugging:

-------------------------------------------------------
PCC-S-02315, cannot evaluate expression as constant
Semantic error at line 18005, column 23, file D:\GC\CoreMSVS2012\..\Server\sql\vendors.pc:
1> char lv_last_changed[triple(20)] = {0};
-------------------------------------------------------

Where triple(20) is an #define to to do some calculation.

It was working good in VS2008, but from VS2012 to VS2013, it is throwing this error. If you know any answer to this, please share here. Thank you!

RobinHood70
February 22, 2015

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

I'm currently getting the same issue with a property in an abstract class. The code is stupidly simple.

public abstract class TestBase<T> : TestBase
{
    protected T Output { get; set; }
}


and then the class using it is a simple:

public class LoginTest : TestBase<LoginOutput>
{
    ...
}


In this case, Output is not being evaluated in the debugger window when I hover over a "this.Output" it in the code. When I hover over "this", I get the window for that and drilling down to Output, I get the "Could not evaluate expression" error with a refresh icon. When I refresh, it tells me that it cannot convert LoginTest to TestBase<LoginOutput>.

If I add in a plain-and-simple backing field, the backing field gets evaluated fine.

So far, none of the solutions presented have helped in the slightest.

Kochise
November 20, 2015

# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality

I've discovered the way to break into native code and have access to STL containers' content when debugging using CLI :

Tools\Options...\Debugging\General : uncheck 'Use Managed Compatibility Mode' (YES! UNCHECK IT!)

In the native code, instead to add breakpoints, just add this :

assert(false);

When breaking against the shores, just click either 'Retry' to debug or 'Ignore' to continue.

Happy debugging with Visual Studio 2015 :)

Kochise

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024