Debugging and the Entity Framework

Introduction

This one’s going to be a little shorter than the normal entries, even though I’m stepping through the maze that are exceptions which can be raised out of using the Entity Framework.

I’m working on some functionality which will ease the pain of POCO object validation, and also cleaning up the data access handling code to be more robust; to handle exceptions more gracefully.  My driver has been to deliver some structured data import functionality (to populate the database), and I’ve come across a couple of “lessons learned” when using detached entities and large object graphs.

Debugging and Timeouts

Due to the large size of the data structures which are wound up into exceptions, depending on how big your object graph is, you might find Visual Studio is serving up to you the following when hitting a breakpoint or on an unhandled exception:

System.Exception: Function evaluation timed out.

Function evaluation timeout

You might find this in this error in the quick watch and watch screens as well.  This, IMHO, renders debugging completely useless.  You lose pretty much everything, the call stack, locals and in my case stepping through didn’t really help either.

The Remedies

I honestly don’t know what’s going on with Visual Studio 2013 & 2012, similar code used to debug (and unwind) just fine in Visual Studio 2010, so I’m assuming it has something to do with the changes to debugging introduced between Visual Studio 2010 and 2012.

Disabling the Exception Assistant

This is the occasionally useful decorated window which pops up when an exception is thrown whilst debugging.

Exception Assistant

The Exception ASSistant in “action”

You can disable the Exception Assistant, or stop it from unwinding the call stack in the Options dialog:

Disable Exception Assistant

In my experience though, disabling the unwind of the call stack didn’t help; only disabling the assistant entirely had any net positive effect.  After disabling the assistant, I didn’t have any further function evaluation timeouts.

Increase Timeout Length

If you really can’t live without the exception assistant, another option is to give Visual Studio more time to do whatever the hell it does when an exception occurs.  Be warned though that this will apply universally to whenever any type of exception occurs!

You’ll need to edit the registry – for the logged on user, browse to the following key:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\Debugger

Increase VS Timeouts

There’s a bunch of timeout keys, but the two major ones are NormalEvalTimeout and QuickwatchTimeout which, I feel, are fairly self explanatory. This worked for me some of the time.

Summary

I’ll keep updating this post as I find more information about what’s going on inside Visual Studio 2013.  For now though, I’m proceeding with the Exception Assistant disabled.

Some Helpful Links

[ http://stackoverflow.com/questions/17772667/function-evaluation-disabled-because-a-previous-function-evaluation-timed-out ]
[ http://stackoverflow.com/questions/787334/how-to-keep-visual-studio-debugger-visualizers-from-timing-out ]
[ http://blogs.msdn.com/b/saraford/archive/2008/08/05/did-you-know-you-can-disable-the-exception-assistant-274.aspx ]

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.