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(MyDataSet),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(MyDataSet));

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

0
lqui001 (2)
1/11/2006 10:34:14 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
680 Views

Similar Articles

[PageSpeed] 1

Probably because DataSet implements IXmlSerializable - meaning it does it's 
own custom serialization.

"Livrish" <lqui001@yahoo.com> wrote in message 
news:1137018854.242920.10090@g47g2000cwa.googlegroups.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(MyDataSet),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(MyDataSet));
>
> 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;
> }
> }
> }
> }
> 


0
chris6851 (20)
1/15/2006 9:10:21 AM
Reply:

Similar Artilces:

Ignore a Value
Hello, I wonder if anybody can help? I wish to ignore a value should it be returned by a formula. There are 3 persons in a list...... Tom, Dick and Harry. Tom has 10 points Dick has 10 points Harry has 5 points I wish to produce a list of leaders which in this case has 2 names ie. Tom and Dick who both have 10 points. But when using VLOOKUP the function defaults with the first of the two names: ie Tom. I wish to ignore the value Tom in the second cell of the list ( 3 cells) so that the value of Dick is returned. Any ideas please since it would work with a IGNORE function. Thanks Laddy ...

Puzzling attribute
Hi all, Does anyone know why the command ActiveWindow.DisplayWorkbookTabs = True or ActiveWindow.DisplayWorkbookTabs = False anywhere in an activeworkbook kicks off the prompt to save a hidden (and untouched) Personal.xlsb when Excel is closed? Kind regards, Bony -- "There are 10 types of people in this world. Those who understand Binary and those who don''t ..." ...

MSXML2 to Load xml document using ISO-8859-1 encoding
HI My application connects to the UPS server which returns an ISO-8859-1 encoded XML response. I need a part of this response, ie. the AccessLicenseAgreement , which i need to display in my application and then return to the UPS server with the next request. Their server matches what they sent me with what i return back to them. Due to the difference in the encoding method it returns an Invalid AccessLicenseAgreement error back to me. I set my request Processing Instruction to ISO-8859-1 encoding, but i still get the same error from them. I am guessing the problem is when i read it in using Lo...

WinUSB
I have a device that presents the standard Bluetooth HCI controller interface on USB. I can successfully open a handle to it via the standard methods (CreateFile, WinUsb_Initialize) and communicate via control transfers with interface 0. However, I want to send a request to interface 2. I initialize my WINUSB_SETUP_PACKET as desired, with the Index field set to 2. But on my USB analyzer, when I see the packet go out, the Index field is 0. Am I missing a call in to the driver to allow or otherwise enable interface #2? What would cause the Index field to change value inside...

Lot Attribute table-IUSCOUNT filed
Hi Folks The Lot Attribute Master table IV00301 has a field called IUSCOUNT. Does anyone understand what that field is all about please? [Ver 10 sp 3] Many thanks Sheila ...

How to create EXE having some XML files ?
Hello there I am designing one application that would create one exe and pack some resources in it(Like some XML files). Is there any way to do this ? If you are unable to understand it, please Let me know. I'd try to elaborate on it more. ...

Modify Appointment Status Code attribute
Hello, Does anyone know how I can modify the pick list values that is for the Status Code attribute in the Appointment Entity. This is the pick list that appears when a user clicks on Actions->Close Appointment. All I can use is Completed or Canceled. However, I would like to add more to the list. When I open the attribute, everything is greyed out and I cannot modify this. Please advise. Thanks Hi Daryl this field is locked because it is a system attribute, and i do not know of any supported ways to customize/change values in this attribute. Regards Leon Agerlin "daryl&...

To ignore scrolling CListCtrl using mouse.
I want to ignore mouse control on a scroll bar of CListCtrl. I ignored WM_VSCROLL, WM_MOUSEMOVE, and WM_MOUSEWHEEL messages on PreTranslateMessage of CListCtrl derived class. But it still works. How to ignore scrolling? I don't want to remove the scroll bar. ...

Protectected cell ignore
How do I prevent the warning message appearing when trying to alter a protected cell. You could have a macro that does the protecting--put it in your auto_open or workbook_open event: Option Explicit Sub auto_open() With Worksheets("sheet1") .Protect Password:="hi" .EnableSelection = xlUnlockedCells End With End Sub Excel won't remember this setting after you close it and reopen the workbook (that's why it's in auto_open). Anthony Byrne wrote: > > How do I prevent the warning message appearing when trying to alter a protected ...

Need help modifying XML file...
I have this xml file... <?xml version="1.0" encoding="utf-8" standalone="yes"?> <images> <pic> <image>http://www.somesite.com/mypic.jpg</image> <caption>Picture 1 is here</caption> </pic> <pic> <image>http://www.somesite.com/mypic2.jpg</image> <caption>Picture 2 is here</caption> </pic> </images> Using VB.NET how could I add, edit and remove a <pic> item, consisting of an <image> and <caption>? Any sample c...

Need Help: outlook 2003 always starts ignoring password
when I start outlook 2003, it always bypass the password I set for PST file. I checked the setting, and am very sure I do not tick the option "save this password in your password list"? Any help is appreciated. Dear, Have you try to recreate a different password - just for a try -- (Please respond to this question Was this post helpful to you?) Hope this helps you more Regards APK "John Kerry" wrote: > when I start outlook 2003, it always bypass the password I set for PST file. > I checked the setting, and am very sure I do not tick the option "save ...

Handling Double Quote in Xml
HI All How Can I handle the Double Quote in xml when i am trying to write the Xml File From XmTextWriter Class in System.Xml NameSpace When I try to Write DoubleQoute(") From dataSet to xml File it Replaces Doubly Quote by (_x0022) by this <_x002_MapName>ProjectName</_x002_MapName> Or If there is Any Comma it does like this <_x002C_MapName>ProjectName</_x002C_MapName> Tell me How Can I handle This Thanks and Regards Amit Goel Project Engineer ..NET group, Global MicroSoft Business Unit (GMSBU) Wipro Technologies, Madhapur, Hyderabad, India Phone: +91-4...

GP10 Integration Manager with XML Input Sources
Hi, Just been setting up my GP10 Test environment and have installed the IM component. The IM setup routine asked me for a User Name and SQL instance for the eConnect component which was accepted by the install as valid. NOW, I don't have any XML Source adapters and my existing XML sourced integrations are ruled as invalid. Can someone tell me what I have doen wrong as to only have ODBC and Text input options to integrations....... (Text !!! Grrrrr). Our Partner is reduced to one line responses in e-mails which are getting shorter and shorter. TIA. Cheers. R. ...

Write dataset to xml and back again to dataset?
Before a delete on any table, I would like to write the contents of the soon-to-be-deleted row to that application's single "graveyard" table (alternate: or document as coded below). SQL Server 2005 solution: I would store the tablename, today's date, username, and the key column values of the soon-to-be deleted row as the composite key of the new graveyard table row. The soon-to-be-deleted row's data would be stored in a single xml-type column. XML File solution: composite key from above would be the name of a filename.xml file. The data from the soon-to-be-deleted...

Format Xml Document in VS2005
On advice of Stan Kitsis on this forum, I was able to format in VS an XML document by Selecting Edit / Advanced / Format document. It worked. But now I am attempting to do the same thing again, with the same xml document, and the format command is no longer on the list. When I press Ctrl-K, Ctrl-D, a message on the status bar says "The key combination (Ctrl+K, Ctrl+D is bound to command (Format Document) which is not currently available." So how do I cause that command to be available again? Thanks, Randy Neall Forget it. I had forgotten I was in a debugging session at the time...

string and xml useage
Am I using strings properly in the code below? The code is working but not sure if my conversions are normal / standard / acceptable. CComPtr <IXMLDOMDocument2> m_pDocument; hr = m_pDocument.CoCreateInstance(CLSID_DOMDocument2); DEBUG_HR(hr); .... add elements to m_pDocument ... // create indented xml CComBSTR bRootXml; CString rootXml; hr = m_pDocument->get_xml(&bRootXml.m_str); DEBUG_HR(hr); rootXml = bRootXml; // add cariage returns between tags rootXml.Replace("><", ">\n<"); TRACE("rootXml:\n%s...

setting timeout in XML controls
Is there a way to set a timeout in either MSXML or in .NET's XML classes? --Buddy Hi, If you're using MSXML4.0 take a look at the ServerXMLHTTP: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_mth_sz_0cj7.asp Regards, Ion Vasilian -- This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm. "Buddy Ackerman" <buddy@buddyackerman.com> wrote in message news:uHqaoAkmDHA.2068@TK2MSFTNGP09.phx.gbl...

Cannot Delete Attribute Maps through API
So it doesn't appear that there is any supported way to manage attribute maps through the CRM API. How can we maintain and distribute CRM customizations to other environments without this capability? Is it just me or is this a serious oversight on Microsofts part. Hi John, Do you mean the attribute mappings between two entities? In that case you should be able to manage them through the CRM API. Just go to Settings -> Customization -> Customize entities -> Open one of the involved entities -> click 1:N or N:1 relationships on the left hand side -> Open a relationsh...

LINQ to XML and Amazon Webservices
Hi, I'm having a hard time in using LINQ on XML returned from Amazon Webservices. I'm using the 2008 beta 2 on an XP machine. the code I'm using is: ========= Dim s As String s = "http://ecs.amazonaws.com/onca/xml?" & _ "Service=AWSECommerceService&" & _ "AWSAccessKeyId=1234&" & _ "AssociateTag=my-tag&" & _ "ResponseGroup=Small&" & _ "Operation=ItemSearch&" & _ ...

XML data entry for given XML schema
Hello, maybe this qustion sounds silly but in VS2005, I'm looking for the same possibilty to entry data for a predefined XML schema in grid view. In VS2003, you were able to do it if you simply set the target schema of your new XML file (which contains nothing besides the xml version line) and switch to data view. This simple way of data entry seems to be gone in VS2005, or is it hidden somewhere else? Thanks Stephan Hofmann Open xml file, right click and select "View Data Grid" -- Stan Kitsis Program Manager, XML Technologies Microsoft Corporation This posting is prov...

SOAP xml
Fedex in the US is changing their method of dealing with their servers for submitting packages, tracking , etc. The old method was a formatted Xml file submitted via an HTTP Post. You then parsed the returned Xml that contained the information requested. Now they are phasing that out in favor of a web service using WSDL SOAP messages. I took one of their VB.Net samples and have sucessfully tracked packages and received Proof of Delivery Pdf files. However I have a problem when I deal with Fedex tech support when I have questions about some of their other services, for example Address ...

Ignore Zero's
Hi I have used the following to get the average value from a set of data whilst ignoring zero values within the data set. =SUM(K4:AP4)/COUNTIF(K4:AP4,">0") I would like to use the percentile command on the same set of data. Is there a way that I can use Percentile and also ignore zero values ? Many Thanks Chris Hi, with an ARRAY formula =PERCENTILE(IF(K4:AP4>0,K4:AP4),0.1) This is an array formula which must be entered by pressing CTRL+Shift+Enter 'and not just Enter. If you do it correctly then Excel will put curly brackets 'around the formu...

DTD ?? and Errors when trying to Retrieve / Read a generated XML f
Hi All Hope someone can help. Using WebRequest.Method = "POST" and ContentType = "application/x-www-form-urlencoded" I connect to a web application which then is expected to return me an XML file ie It is generated and returned rather than existing as a file in a location. my webrequest reads as... http://webedu/webct/public/serve_webctdb?OPERATION=homearea_xml From the Browser I get this returned <?xml version="1.0" standalone="no" ?> <!DOCTYPE homearea (View Source for full doctype...)> - <homearea base="http:...

XML XSL FO PDF
Can I use XML->XSL->FO->PDF in .NET? I have the XSL FO from XML, and now use client based FOP software. I have seen a few commercial packages for FO->PDF but they are costly (1000 dollars). news wrote: > Can I use XML->XSL->FO->PDF in .NET? Sure but only with some third-part library. .NET doesn't support XSL-FO natively. -- Oleg Tkachenko [XML MVP] http://blog.tkachenko.com I am using FOP which I downloaded from somewhere (forgotten), can you recommend anything for the FO handling? I found the XSL a dream in .NET and hoped that .NET had something intrinsic ...

Escape codes embedded in XML
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1 QID=\"55111\"><Tag2 AID=\"5511101\"></Tag2></Tag1><Tag1 QID=\"55112\"><Tag2 AID=\"5511217\"></Tag2></Tag1><Tag1 QID=\"5512282\"><Tag2 AID=\"551228206\"></Tag2></Tag1><Tag1 QID=\"55114\"><Tag2 AID=\"5511406\"></Ta...