Lazy Loaded Properties And Visual Studio's Debugger

posted on 09/06/07 at 10:54:33 pm by Joel Ross

I'm working on some framework code tonight, and I'm struggling with one issue that I can't seem to find any information about. We lazy load a lot of properties for speed reasons, which works out great for us. The problem comes when you need to debug them. Here's a customer object from the Northwinds database while debugging in Visual Studio 2005:

DebuggerFillsLazyLoadedProperties

All I've done so far is get it. The Orders property is lazy loaded and hasn't been accessed in code yet, but it shows a count of 12 - it gets loaded as a result of examining the customer object in the debugger.

Thus far, I haven't heard anyone complain about this, but the fact that you could now get two different behaviors from an object depending on whether you've debugging it or not isn't a good thing.

Any ideas of what to do about this? All of our lazy loaded properties have a private field behind them, so I could show the fields instead, but that doesn't sound like a clean solution to me.

Tags: ,

Categories: Development, C#