Sunday, August 3, 2014

Datacontractserializer and Namespace

Hi, I have a problem trying to deserialize an xml file created from a different namespace. The code I use is



file = await ApplicationData.Current.LocalFolder.GetFileAsync("EortologioMovingEntries.xml");
try
{
using (IRandomAccessStream stream =
await file.OpenAsync(FileAccessMode.Read))
using (Stream inputStream = stream.AsStreamForRead())
{
DataContractSerializer serializer = new DataContractSerializer(typeof(Anniversaries), "Anniversaries", "http://ift.tt/1rZiihn;);
tempAnniversaries = serializer.ReadObject(inputStream) as Anniversaries;
}
}
catch (Exception ex)
{
error = ex.ToString();
tempAnniversaries.Entries.Add(new AnniversaryEntry("Ena", DateTime.Now, "skata", PriorityEnum.High));
}

Eortologio.Model is the namespace that the file was created. I don't get any exceptions but the tempAnniversaries returns null.


this is the start of the xml file.



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:Anniversaries xmlns:ns2="http://ift.tt/1rZiihn; xmlns:xsi="http://ift.tt/1m4M9U6;
<ns2:Entries>
<ns2:AnniversaryEntry>
<ns2:anniversaryName>Τελώνου και Φαρισαίου - Αρχή Τριωδίου</ns2:anniversaryName>
<ns2:anniversaryPriority>Medium</ns2:anniversaryPriority>
</ns2:AnniversaryEntry>
<ns2:AnniversaryEntry>
<ns2:anniversaryName>Του Ασώτου</ns2:anniversaryName>
<ns2:anniversaryPriority>Medium</ns2:anniversaryPriority>
</ns2:AnniversaryEntry>



Any ideas? Thank you.




No comments:

Post a Comment