Contact   •   Products   •   Search

Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs

Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality


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…

Make Donation
Posted in ASP.NET   Visual Studio  


Feedback for this Post

 
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Martin November 22, 2013 @ 5:25am
Helped me alot, thank you!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Anup November 26, 2013 @ 5:31am
Many thanks for this. I kept getting this. Deleting the breakpoints and reattaching to debug again was all that was needed.
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Knipjo November 27, 2013 @ 2:41am
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
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Joe Capka December 05, 2013 @ 1:38pm
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.
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Dieter Wiesflecker December 10, 2013 @ 8:33am
thanks, had the same problem, it occured just during woring in a Webservice, after enabeling managed Comp Mode it worked again!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Gage January 07, 2014 @ 11:07am
Thanks for the tip. I had the same problem migrating solutions from VS2010 and clearing all of the breakpoints fixed the problem.
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Lotux January 24, 2014 @ 7:35am
Thansk a lot it was driving me mad :)
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Jakub January 25, 2014 @ 4:02am
This saved me, thanks!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by John February 07, 2014 @ 7:59am
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!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Ilia March 10, 2014 @ 4:12am
Had the same issue. Deleting breakpoints removed the problem. Thank you very much!!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Johan March 18, 2014 @ 2:45am
Thanks! Saved me a lot of head-scratching! :-)
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by David Madi March 18, 2014 @ 2:22pm
Helped me a lot. Thanks.
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Tim March 25, 2014 @ 4:08am
All of my team have been experiencing the same issue. Cheers for that!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Claudio March 26, 2014 @ 10:50pm
It simply works like that!

Thanks a Lot!
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Andrew Hall March 31, 2014 @ 9:59am
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
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Rob April 04, 2014 @ 7:42am
Andrew -

Typical Microsoft link you provided above -- already expired :(
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Maria Ghiondea - MSFT April 17, 2014 @ 11:04am
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
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Ben Jones April 22, 2014 @ 2:17am
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! :)
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by kris April 24, 2014 @ 12:55am
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 :)
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by clau137 April 28, 2014 @ 7:49am
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.
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Rick Strahl April 28, 2014 @ 1:43pm
@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.
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Guy Kroizman June 01, 2014 @ 4:53am
There is an update from MS. http://stackoverflow.com/a/22642345/193016
# re: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality
by Chan Pal November 07, 2014 @ 5:14pm
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!
 


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