41

I'm experiencing a lot of problems with Entity Framework 6.0.1 in the VS2013 Ultimate debugger when debugging into unit tests against code that's hitting a live SQL Server.

Variables that contain entities can't be viewed in the debugger. For example, if I execute a LINQ query against my DbContext and refresh the results view to actually execute the query, the Results value is "children could not be evaluated". If I ToArray() it, so now the variable is an array of entities instead of an IQueryable, each result in the array is "Could not evaluate expression". If I store a single entity value from that array to a variable and try to view it, I get "The runtime has refused to evaluate the expression at this time."

"The runtime has refused to evaluate the expression at this time"

Frequently, F10'ing through a line that involves access to an entity property causes Visual Studio to crash.

This doesn't happen if I'm running the test against a mocked-up fake DbSet.

Is this a known issue? Is there a way to fix this?

nlawalker
  • 6,364
  • 6
  • 29
  • 46
  • Is the generic type of the DbSet the same in the mocked up case? Maybe the entity type has a property, maybe some sort of computed property you created, which is throwing an exception. Just speculating. – AaronLS Nov 07 '13 at 18:28

5 Answers5

86

I am having a similar problem and although I'm yet to understand why, turning Options -> Debugging -> General -> Use Managed Compatibility Mode - On, allowed me to continue debugging as normal.

I found this option via this blog post.

MrEdmundo
  • 5,105
  • 13
  • 46
  • 58
  • Wow, thanks! I have having the same problem when sandboxing IronPython in an AppDomain and trying to debug uncaught exceptions. This saves me a lot of headache :) – ekolis Dec 27 '13 at 14:12
  • Awesome. I had this problem when I was using WebClient to make http requests between 2 solutions. If I debugged the solution the calls were targeting, the expressions didn't evaluate there. Thanks, this fixed it – parliament Mar 26 '14 at 06:47
  • This worked for me. I disabled **Use Managed Compatbility Mode** right after and debugging continued to work. – sparebytes Apr 28 '14 at 19:48
  • Anyone know why this is the case? Conditional breakpoints are crucial when you're debugging within loops. I don't see why they'd relegate conditional breakpoints to the legacy debugger only. – oscilatingcretin Sep 02 '15 at 14:09
  • 1
    One thing to add is that you need to shut down your debugger before this option becomes available. Otherwise it's grayed out: https://stackoverflow.com/questions/21166874/unable-to-evaluate-expression-whilst-debugging – Catalin Hritcu Feb 11 '17 at 11:13
7

Shortly after installing VS2013, I also encountered the error

"Could not evaluate expression"

for numerous variables while debugging an older VS2012 solution (none of the code involved the entity framework).

The fix that worked was deleting the two Solution User Options (*.suo) files associated with the solution file. For example, for MySolution.sln, the two corresponding files were:

  • MySolution.v11.suo (VS2012 version)
  • MySolution.v12.suo (VS2013 version)

It seems that the v12 version might have been corrupted when it was initially created using the settings from the v11 version. Hence, deleting both of them allowed for a new clean .suo file to be created for VS2013 and the problem went away.

(Note, the .suo files are marked as hidden on Windows 7 so you might not easily see them in Windows Explorer without either changing the settings to show them or using the command line to view them.)

Ray
  • 187,153
  • 97
  • 222
  • 204
  • This also fixed my issue but it wasn't going from VS2012 to VS2013 but instead just updating VS2013 to Update 3. – kjbartel Sep 02 '14 at 04:15
0

There may be a problem regarding debugging if there are any entity with Virtual entities inside. We had this problem when trying to debug at entities inside Ef scope. Entity Framework then try to catch the state of the virtial entities.

We got a better result while viewing the entities outside db scope. This way EF is not involved while watching the entities values.

0

Visual Studio 2013 Update 2 promises to fix this error, found in the comments at:

http://weblog.west-wind.com/posts/2013/Nov/21/Visual-Studio-2013-Could-not-evaluate-Expression-Debugger-Abnormality

Nick
  • 784
  • 8
  • 12
0

I just wanted to add my voice to the crowd here.

I am developing a UWP app, not using the Entity Framework, and experienced a similar issue where the runtime "refused to evaluate the expression".

I was using Microsoft Visual Studio Enterprise 2015 Update 2 and the solution for me was for me to update to Update 3.

Zach Olivare
  • 3,805
  • 3
  • 32
  • 45