This is one of those posts that I’m partially putting up here so I don’t forget this later.
I’m currently working on a data integration project that involves the basic process of sending and retrieving data from a third party web service. When retrieving data, the Service Reference creates proxy classes for the objects being returned. So far, nothing special.
Before using this data, I needed a clean way to turn the web service objects into my own business objects so that I can manipulate and save the data using our normal application business/data layer code. One of our partners, Jerry Brunning, suggested partial classes would be a good approach for this and it worked great. Basically I just have a partial class for each web service data object I’m consuming and they typical have one method: ToMyBusinessObject, although there are some helper classes scattered in there as well. So far, still a pretty typical way to do it.
The problem came when I started debugging and needed to step into the partial classes to make sure my mappings were working properly. I would be stepping through my consuming code just fine and then all of a sudden the next use of F10 or F11 resulted in skipping whole chunks of my partial class code. The debugger would stop if there was a breakpoint in the partial class. Baffling behavior.
I thought my development environment had gotten messed up, so I messed with some settings and other stuff. Tried on someone else’s computer, but same behavior. About that time, Mike Frank suggested checking the attributes of the automatically generated code in the Service Reference classes, specifically the Reference.cs file. Sure enough,there was an attribute on each class that looked worth checking,the System.Diagnostics.DebuggerStepThroughAttribute. When I looked it up, the purpose of this attribute is “Instructs the debugger to step through the code instead of stepping into the code”. I guess I get why Microsoft decided this should be the default for IDE generated code, but it certainly wasn’t very discoverable. You also can’t put a different attribute on your partial class, so the only way around it is to edit the generated code and remove the attribute. And you have to remember to do this every time you update your service reference. Still, since this is really only something you need during development for the most part, it’s not too bad. Just hard to diagnose.
Comments Off , permalink



