Debugging Deserialization Exceptions
I hit a snag recently while using web services hosted under Websphere in a c# client. I was getting an invalid format exception when invoking the web service; the service's author had no idea what the problem was; it generated valid WSDL, and the problem occurred at runtime. The XML looked OK.
So how do you go about debugging the deserialization process at runtime?
The serializer creates source code at runtime and compiles it into a randonly-named assembly, before deleting the source. It's possible to keep that source code, and debug into it.
1. Put the following in your config file:
<switches>
<add name="XmlSerialization.Compilation" value="4" />
</switches>
</system.diagnostics>
This will force the serializer to leave the source code lying around, rather than deleting it.
2. Keep your eye on the output window as you launch your app; you're looking for an oddly named assembly being loaded, such as 7dr9bhsr.dll; this is the assembly generated by the deserializer at runtime, and it's name will change every time your app is run;
3. Look in your temp folder (C:\Documents and Settings\
4. dbl-click on the .cs file to open it in VS;
5. Under Debug Exceptions, make sure you are breaking into the debugger when the exception is thrown;
6. Run your app to recreate the problem that causes your exception;
7. The debugger will break on the line in fault in the source code file;
You can then step through the code, and work out exactly what is failing to be deserialized...

0 Comments:
Post a Comment
<< Home