I am using the following code to compare types so that a DataContractSerializer will re-initialize with the correct type if necessary.
private void InitializeSerializer(Type type)
{
if (this.serializer == null)
{
this.serializer = new DataContractSerializer(type);
this.typeToSerialize = type;
}
else
{
if (this.typeToSerialize != null)
{
if (this.typeToSerialize.GetType() != type.GetType())
{
this.serializer = new DataContractSerializer(type);
this.typeToSerialize = type;
}
}
}
}
For some reason when I compare the two types the result is always true and I never enter the final 'if' statement and re-initialize my serialiser.
I can set a break point at the comparison and clearly see that the two types are
List<Host>
(this.typeToSerialize.GetType()) and
Post
(type.GetType())
Both Host and Post share a common ancestor but that shouldn't be affecting the result.