Debugging .NET Serialization Code

25 02 2008

Just what is your XmlSerializer doing?

You can find out by debugging the serialization code which is generated automatically at runtime;

1. Modify your .config file to include the following snippet

<configuration>
   <system.diagnostics>
      <switches>
         <add name="XmlSerialization.Compilation" value="1" />
      </switches>
   </system.diagnostics>
</configuration>

2. Rebuild your code and set a breakpoint on or just after where you create an instance of the XmlSerializer, but before you call Serialize() or Deserialize().

3. Navigate to the temp directory in your profiles local settings directory

For Vista this is [C:\Users\{user}\AppDataLocalTemp]

For Win XP+ this is [C:\Documents and Settings\{user}\Local Settings\Temp]

4. In Visual Studio, open the most recent .cs file from this folder, set a break point and away you go.
 

Technorati Tags: ,,,,




Serialisation in C# 3.0

21 12 2007

This is a great article demonstrating Serialisation in C# 3.0 including the DataContractSerializer.

O’Reilly C# 3.0 in a Nutshell