VS2013 Debugger + Entity Framework: "runtime has refused to evaluate the expression", crashes

c# debugging entity-framework linq visual-studio-2013


When debugging into unit tests against code that is accessing a live SQL Server, Entity Framework 6.0.1 with the VS2013 Ultimate debugger is giving me a lot of issues.

Entity-containing variables cannot be examined in the debugger. For instance, the Results value is "children could not be evaluated" if I run a LINQ query against my DbContext and reload the results view to actually run the query. Each result in the array is "Could not evaluate expression" if I use the ToArray() function, which turns the variable into an array of entities rather than an IQueryable. The runtime has refused to evaluate the expression at this time if I try to view a single entity value from that array that I've stored in a variable.

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

F10ing across a line with access to an entity property frequently results in Visual Studio crashing.

If I run the test against a mocked-up false DbSet, this doesn't occur.

Is this problem well-known? Can this be fixed in any way?

11/7/2013 6:22:16 PM

Accepted Answer

Although I still don't know why, turning Use Managed Compatibility Mode under Options -> Debugging -> General. - On allowed me to resume debugging even though I was having a similar issue.

I discovered this choice through this blog entry.

11/28/2013 10:20:33 AM

Popular Answer

I also ran into the error soon after installing VS2013.

"Could not evaluate expression"

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

The two Solution User Options (*.suo) files linked to the solution file were deleted, and this was the solution that worked. For instance,MySolution.sln the two matching files were as follows:

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

It appears that the v12 version may have been tainted when it was initially made using the v11 version's settings. Consequently, removing both of them made room for a fresh, clean.suo the VS2013 file to be produced, and the issue was fixed.

(Note the the.suo On Windows 7, files can be marked as hidden, making it difficult to access them in Windows Explorer without either altering the settings to make them visible or the command line.)

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow