I'm porting a Windows 7 app to a Windows 8 Store app. In both cases, I'm able to use DataContractSerializer to populate classes by reading in an XML file.
The problem I'm having is that my list of known types (Data1 through Data5) all inherit from MyBase class that contains an Id property. In the Windows 7 version, the Id is populated as expected. In Windows 8 RT, the Id is NOT being populated.
The only difference in the code is that the Windows 7 version of DataContractSerializer offer a IgnoreExtensionDataObject parameter, which I set to false (and this works on Windows 7). On WinRT, there's no such parameter to DataContractSerializer.
My question: Has anyone run into this before, and is there an equivalent or alternative setting available.
Thanks...
Windows 7 Code that Works:
DataContractSerializer serializer =
new DataContractSerializer(typeof(MyQuery),
new List<Type>{typeof(Data1), typeof(Data2), typeof(Data3),
typeof(Data4), typeof(Data5)},
int.MaxValue, false, true /* preserve object refs */, null);
using (FileStream fs = new FileStream(_file, FileMode.Open))
{
Model = (MyQuery)serializer.ReadObject(fs);
}
Windows RT Code that Works Except that the Base Class Id property not populated:
List<Type> listOfTypes = new List<Type>
{
typeof(Data1),
typeof(Data2),
typeof(Data3),
typeof(Data4),
typeof(Data5)
};
DataContractSerializerSettings dataContractSerializerSettings = new DataContractSerializerSettings();
dataContractSerializerSettings.MaxItemsInObjectGraph = int.MaxValue;
dataContractSerializerSettings.PreserveObjectReferences = true;
dataContractSerializerSettings.KnownTypes = listOfTypes;
DataContractSerializer serializer =
new DataContractSerializer(typeof(MyQuery), dataContractSerializerSettings);
Stream stream = await storageFile.OpenStreamForReadAsync();
Model = (MyQuery)serializer.ReadObject(stream);
Randy