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

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

Question

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?

1
38
11/7/2013 6:22:16 PM

Accepted Answer

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.

82
11/28/2013 10:20:33 AM

Popular Answer

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.)



Related Questions





Related

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