XmlSerializer much slower when a different constructor for it is used

24 Views Asked by At

In .NET 2 I have the following code, which works okay:

public static T DeserializeStream<T>(this Stream xmlStream)
{
    XmlSerializer serializer = new XmlSerializer(typeof(T));
    using (XmlReader xmlReader = XmlReader.Create(xmlStream))
    {
        return (T)serializer.Deserialize(xmlReader);
    }
}

however when I change the constructor to the more specific kind but fill it with blank values the code runs at least 5x slower when I run it on a large list of files of the same type:

XmlSerializer serializer = new XmlSerializer(typeof(T), null, Type.EmptyTypes, null, null);

Why is this? Is this expected? Does this stop it caching some sort of type data?

0

There are 0 best solutions below