I’m currently having a really weird issue and I can’t seem to figure out how to resolve it.
I’ve got a fairly complex type which I’m trying to serialize using the XmlSerializer class. This actually functions fine and the type serializes properly, but seems to take a very long time in doing so; around 5 seconds depending on the data in the object.
After a bit of profiling I’ve narrowed the issue down – bizarrely – to specifying an XmlRootAttribute when calling XmlSerializer.Serialize. I do this to change the name of a collection being serialized from ArrayOf to something a bit more meaningful. Once I remove the parameter the operation is almost instant!
Any thoughts or suggestions would be excellent as I’m entirely stumped on this one!
Just for anyone else who runs into this problem; armed with the answer above and the example from MSDN I managed to resolve this issue using the following class:
Then instead of using the default XmlSerializer constructor which takes an XmlRootAttribute, I use the following instead:
My application is now performing again!