nlawalker nlawalker - 3 years ago 222
C# Question

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

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download