473,385 Members | 1,486 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.

Exception while creating XmlSerializer with XmlAttributeOverrides.

I am using XmlSerializer with XmlAttributeOverrides. The
XmlAttributeOverrides are used for properties which hold element/s
derived from "AbstractMessage" type.

System.Xml.Serialization.XmlRootAttribute(Namespac e = "http://
www.TestNameSpace.org/Test-4-4", IsNullable = false)]
class Root
{
[System.Xml.Serialization.XmlElementAttribute(Type =
typeof(Abstract_message), ElementName = "Message", IsNullable =
false)]
public virtual Abstract_message Message
{
get { return this._messageField; }
set{ this._messageField = value; }
}

[System.Xml.Serialization.XmlElementAttribute(Type =
typeof(BatchMesssage), ElementName = "Batch", IsNullable = false)]
public virtual Batch_tCollection Batch
{
get { return this._batchField; }
set{ this._batchField = value; }
}
}

[System.Xml.Serialization.XmlTypeAttribute(Namespac e = "http://
www.TestNameSpace.org/Test-4-4")]
public class BatchMesssage
{
///
[System.Xml.Serialization.XmlElementAttribute("Hdr" , Order =
0, IsNullable = false)]
public BatchHeader_t Hdr
{
get{ return this._hdrField; }
set { this._hdrField = value; }
}
[System.Xml.Serialization.XmlElementAttribute("Mess age", Order
= 1, IsNullable = false, Type = typeof(Abstract_message_t))]
public Abstract_message_tCollection Messages
{
get { return this._messageField; }
set { this._messageField = value; }
}
}

where type "Batch_tCollection" is a collection of "BatchMessage" type
items.
For type "Root" "BatchMessage" I provide XmlAttributeOverrides for
property "Message" & "Messages" respt. :

System.Xml.Serialization.XmlAttributeOverrides attribOverrides = new
System.Xml.Serialization.XmlAttributeOverrides();
System.Xml.Serialization.XmlAttributes msgAttribs = new
System.Xml.Serialization.XmlAttributes();
msgAttribs.XmlElements.Add(new
System.Xml.Serialization.XmlElementAttribute("Test MessageRoot",
typeof(TestMessage)));
attribOverrides.Add(typeof(Root), "Message", msgAttribs);
attribOverrides.Add(typeof(BatchMesssage), "Message", msgAttribs);

where type "TestMessage" is derived from "AbstractMessage" type.
When I try to instantiate the XmlSerializer with the above
XmlAttributeOverrides as parameter to the constructor it throws the
following exception:

Exception:
System.InvalidOperationException was caught
Message="There was an error reflecting type 'Root'."
Source="System.Xml"
StackTrace:
at
System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType,
XmlAttributes a, Boolean repeats, Boolean openModel)
at
System.Xml.Serialization.XmlReflectionImporter.Imp ortElement(TypeModel
model, XmlRootAttribute root, String defaultNamespace)
at
System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(Type
type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type,
XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute
root, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer..ctor(Type type,
XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute
root, String defaultNamespace)

Inner Exception: There was an error reflecting property 'Batch'.
Inner Exception: There was an error reflecting type 'BatchMessage'.
Inner Exception: Inconsistent sequencing: if used on one of the
class's members, the 'Order' property is required on all particle-like
members, please explicitly set 'Order' using XmlElement, XmlAnyElement
or XmlArray custom attribute on class member 'Messages'.
In the above case if I remove the sequencing property ("Order") from
the XmlElementAttribute applied on BatchMessage member properties, the
thing seems to work correctly.

Am I using the XmlAttributeOverride in the right place? Any help on
the above will be appreciated.
Thanks in advance.

Jun 21 '07 #1
0 4060

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

Similar topics

4
by: Zion Zadik | last post by:
Dear all, I have a set of c# data classes which i need to fill their data from xml files. serialization looks to be the best way to accomplish this task. Since the data classes are compiled and...
5
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
4
by: Alexis | last post by:
Hello, Is there a way of telling the XmlSerializer to ignore all namespaces when deserializing. I'm using XmlAttributeOverrides, but I have to do it for every class the OutputObject usses. Is...
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
3
by: Roy Chastain | last post by:
The following code fails with an exception of "There is an error in XML document (2, 2)." string with an inner exception of "Value cannot be null.\r\nParameter name: input" string. The inner...
1
by: Zion Zadik | last post by:
Dear all, I have a set of c# data classes wich i need to fill their data from xml files. serialization looks to be the best way to accomplish this task. Since the data classes are compiled and i...
3
by: Kishore Gopalan | last post by:
Hi, I have the following class. Assembly: A.dll public class Customers { public Customer customer; } public class Customer { public string name;
5
by: Nathan Wiegman | last post by:
Using the XmlSerializer to deserialize a double.NaN value generates an exception in the framework which the framework then catches. This is super undesirable in our application, because our...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.