NetDataContractSerializer and CLR types
See the question and my original answer on StackOverflowIt depends on the types. NetDataContractSerializer
is based on types full type name, possibly qualified with the assembly full name. For example, this code:
List<string> list = new List<string>();
list.Add("joe");
list.Add("sam");
NetDataContractSerializer ser = new NetDataContractSerializer();
using (FileStream stream = File.OpenWrite("test.xml"))
{
ser.Serialize(stream, list);
}
compiled using CLR 2 will produce this:
<ArrayOfstring z:Id="1" z:Type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" z:Assembly="0" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"><_items z:Id="2" z:Size="4"><string z:Id="3">joe</string><string z:Id="4">sam</string><string i:nil="true"/><string i:nil="true"/></_items><_size>2</_size><_version>2</_version></ArrayOfstring>
and the same compiled using CLR 4 will produce this:
<ArrayOfstring z:Id="1" z:Type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" z:Assembly="0" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"><_items z:Id="2" z:Size="4"><string z:Id="3">joe</string><string z:Id="4">sam</string><string i:nil="true"/><string i:nil="true"/></_items><_size>2</_size><_version>2</_version></ArrayOfstring>
As you see, there are not compatible because they include System.String
's assembly qualified full name. So it will depend on what you do, but chances are good that it will not work as is. I don't have a 4.5 setup at hand, but you could test it directly.