Hey
I have having a problem Deserializing a dataset. When I try to
deserialize it (See below for my test code) I get the following
exception
{"Item has already been added. Key in dictionary: \"NextSyncPhase\"
Key being added: \"NextSyncPhase\"" }
But if I remove either msdata:NextSyncPhase="Hello" or
msprop:NextSyncPhase="Hello" (see below) it works fine!
Can anyone explain why XmlIgnore doesn't impact anything and why this
is happening and how to fix it
Thanks
P.S. I also tried the following to no affect.
XmlAttributeOverrides xOver = new XmlAttributeOverrides();
XmlAttributes attrs = new XmlAttributes();
// attrs = new XmlAttributes();
// attrs.XmlIgnore = true;
//xOver.Add(typeof(MyDataSet), "NextSyncPhase", attrs);
// m_serializer = new
System.Xml.Serialization.XmlSerializer(typeof(MyDa taSet),xOver);
<?xml version="1.0"?>
<MyDataSet>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="en-NZ" msdata:NextSyncPhase="Hello"
msprop:NextSyncPhase="Hello">
<xs:complexType>
<xs:choice maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" />
</MyDataSet>
using System;
using System.Data;
namespace XmlSerialization
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
try
{
MyDataSet myDataSet ;
//if(System.IO.File.Exists("test.dac"))
// myDataSet = EncryptionSupport.Instance.Decrypt("test.dac");
myDataSet = new MyDataSet();
myDataSet.NextSyncPhase = "Hello";
System.Xml.Serialization.XmlSerializer m_serializer = new
System.Xml.Serialization.XmlSerializer(typeof(MyDa taSet));
using( System.IO.FileStream fileStream = new
System.IO.FileStream("test.dac",System.IO.FileMode .Create))
{
m_serializer.Serialize(fileStream, myDataSet);
}
using(System.IO.FileStream fileStream = new
System.IO.FileStream("test.dac",System.IO.FileMode .Open))
{
myDataSet = (MyDataSet )m_serializer.Deserialize(fileStream);
}
}
catch(Exception ex)
{
return ;
}
}
}
public class MyDataSet:DataSet
{
public MyDataSet():base()
{
//
// TODO: Add constructor logic here
//
}
//================================================== =================
[System.Xml.Serialization.XmlIgnore]
public string NextSyncPhase
{
get
{
if(ExtendedProperties["NextSyncPhase"] == null)
return "Refresh";
return ExtendedProperties["NextSyncPhase"].ToString();
}
set
{
ExtendedProperties["NextSyncPhase"] = value;
}
}
}
}