473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Xml Seralization Ignore attribute

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;
}
}
}
}

Jan 11 '06 #1
1 4364
Probably because DataSet implements IXmlSerializable - meaning it does it's
own custom serialization.

"Livrish" <lq*****@yahoo.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
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;
}
}
}
}

Jan 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: macgyver | last post by:
This is a strange question, and I think the answer is NO, but I am asking anyway. I am a member of a website which allows us to alter our member profiles. Using css in the middle of the profile...
5
by: Damon | last post by:
I'm getting '', hexadecimal value 0x02, is an invalid character when I'm deseralizing XML from a 3rd party XML gateway. How do I get rid of these hexadecimal values before I deserialize? Cheers...
5
by: Alisa | last post by:
How can i get the seralization of an object as string? Can i avoid saving a temporary file? thanks
14
by: Dario de Judicibus | last post by:
I think that is really important to have the «src» attrinbute in tags other than «img» in order to include XHTML fragments without depending on server-side mechanisms as ISS or PHP. For example: ...
3
by: daldridge | last post by:
Is there anyway to use the contents of a variable as the value of the 'name' attribute of an <xsl:attribute>? Suppose I have this XML input: <Foo> <Bar>Baz</Bar> </Foo>
19
by: Bert Lancaster | last post by:
I'm not actually using it on the web but can anyone tell me why the ID attribute on a <style> tag causes an error in the W3C validator for an XHTML 1.1 document? It doesn't have a problem for a...
1
by: Marek | last post by:
I use VS2005 with framework 2.0 and I just found a behavior I consider odd. Here is the code that illustrates th eproblem: public static void MethodA() { MethodB() } #if DEBUG
4
by: Mark | last post by:
Hi, I am trying to port an application for ASP.NET 1.1 to ASP.NET 2.0. Why am I getting "Error 1 Validation (Internet Explorer 6): Attribute 'ms_2d_layout' is not a valid attribute of element...
7
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
How do I split a title attribute value into lines within the source code so that the paragraph gets reassembled by the browser when it is being displayed? Microsoft Internet Explorer 7 preserves...
0
by: archana | last post by:
Hi all, I have read in one article that code-behind is ignore by asp.net parser. Only src attribute is used by asp.net parser. So my doubt here is if src attrribue is used by asp.net parser...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.