Error in deserializing xml string into object which have namespace

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="color:Black;background-color:White; <pre>
I have an XML


<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; DeliveryApptShellUpdateRequest <span style="color:Red; xmlns:mailxml<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://idealliance.org/maildat/Specs/md091/mailxml80B/mailxml<span style="color:Black; "
<span style="color:Red; xmlns:mailxml_base<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://idealliance.org/maildat/Specs/md091/mailxml80B/base<span style="color:Black; "
<span style="color:Red; xmlns:xsi<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/2001/XMLSchema-instance<span style="color:Black; "
<span style="color:Red; xsi:schemaLocation<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://idealliance.org/maildat/Specs/md091/mailxml80B/mailxml mailxml_121409.xsd http://idealliance.org/maildat/Specs/md091/mailxml80B/base mailxml_base_120409.xsd<span style="color:Black; "
<span style="color:Red; mailxml:ShipperApptRequestID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 020214481606<span style="color:Black; " <span style="color:Red; mailxml:SchedulerCorpID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 012345678933<span style="color:Black; " <span style="color:Red; mailxml:SchedulerID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 012345678901<span style="color:Black; " <span style="color:Red; mailxml:ConsigneeApptID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 123456789<span style="color:Black; " <span style="color:Red; mailxml:ApptType<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Pallet<span style="color:Black; " <span style="color:Red; mailxml:PickupOrDelivery<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Delivery<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; SubmittingParty <span style="color:Red; mailxml:CRID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1223456<span style="color:Black; " <span style="color:Red; mailxml:MaildatUserLicense<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; A111<span style="color:Black; " <span style="color:Red; mailxml:MailerID6<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 123456<span style="color:Black; " <span style="color:Red; mailxml:SchedulerID<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 012345678901<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; SubmittingSoftware <span style="color:Red; mailxml:SoftwareName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ShipmentAssurety<span style="color:Black; " <span style="color:Red; mailxml:Version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 7.0.00<span style="color:Black; " <span style="color:Red; mailxml:Vendor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Assurety Consulting Inc<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; ConsigneeFacility<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; CompanyName<span style="color:Blue; >S--WASHINGTON<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; CompanyName<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; FacilityNumber<span style="color:Blue; >EV21176 <span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; FacilityNumber<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; ConsigneeFacility<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; MailClass<span style="color:Blue; >2<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; MailClass<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; OneTimeAppt<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; PreferredAppt<span style="color:Blue; >2011-02-05T07:00:00<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; PreferredAppt<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; OneTimeAppt<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; TrailerInfo<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; Trailer<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; TrailerLength<span style="color:Blue; >53ft<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; TrailerLength<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; Trailer<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; Carrier<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; CarrierName<span style="color:Blue; >N/A<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; CarrierName<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; URL<span style="color:Blue; >http://assuretyconsulting.com/<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; URL<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; Carrier<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; BillOfLadingNumber<span style="color:Blue; >N/A<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; BillOfLadingNumber<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; TrailerInfo<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; mailxml<span style="color:Blue; :<span style="color:#A31515; DeliveryApptShellUpdateRequest<span style="color:Blue; >
[/code]
<br/>
which I wanted to deserialized into the class DeliveryApptShellUpdateRequest1<br/>
<br/>
<br/>
My class is given as follows [generated by adding web reference link]

<div style="color:Black;background-color:White; <pre>
[System.CodeDom.Compiler.GeneratedCodeAttribute(<span style="color:#A31515; "System.Xml", <span style="color:#A31515; "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(<span style="color:#A31515; "code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=<span style="color:Blue; true, Namespace=<span style="color:#A31515; "http://idealliance.org/maildat/Specs/md091/mailxml80B/mailxml")]
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class DeliveryApptShellUpdateRequest1 : <span style="color:Blue; object, System.ComponentModel.INotifyPropertyChanged {

<span style="color:Blue; private participantIDType submittingPartyField;

<span style="color:Blue; private submittingSoftwareType submittingSoftwareField;

<span style="color:Blue; private consigneeFacilityType consigneeFacilityField;

<span style="color:Blue; private mailClassType[] mailClassField;

<span style="color:Blue; private <span style="color:Blue; object itemField;

<span style="color:Blue; private trailerInfoType trailerInfoField;

<span style="color:Blue; private <span style="color:Blue; string commentField;

<span style="color:Blue; private <span style="color:Blue; string shipperApptRequestIDField;

<span style="color:Blue; private <span style="color:Blue; string consigneeApptIDField;

<span style="color:Blue; private <span style="color:Blue; string schedulerIDField;

<span style="color:Blue; private <span style="color:Blue; string schedulerCorpIDField;

<span style="color:Blue; private <span style="color:Blue; string schedulerCRIDField;

<span style="color:Blue; private <span style="color:Blue; string shipperMultiStopIDField;

<span style="color:Blue; private <span style="color:Blue; string consigneeMultiStopIDField;

<span style="color:Blue; private <span style="color:Blue; string shipperStopNumberField;

<span style="color:Blue; private apptTypeType apptTypeField;

<span style="color:Blue; private pickupOrDeliveryType pickupOrDeliveryField;

<span style="color:Blue; private <span style="color:Blue; string palletPositionCountField;

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
<span style="color:Blue; public participantIDType SubmittingParty {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.submittingPartyField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.submittingPartyField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "SubmittingParty");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
<span style="color:Blue; public submittingSoftwareType SubmittingSoftware {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.submittingSoftwareField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.submittingSoftwareField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "SubmittingSoftware");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=2)]
<span style="color:Blue; public consigneeFacilityType ConsigneeFacility {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.consigneeFacilityField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.consigneeFacilityField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ConsigneeFacility");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(<span style="color:#A31515; "MailClass", Order=3)]
<span style="color:Blue; public mailClassType[] MailClass {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.mailClassField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.mailClassField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "MailClass");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(<span style="color:#A31515; "OneTimeAppt", <span style="color:Blue; typeof(oneTimeApptType), Order=4)]
[System.Xml.Serialization.XmlElementAttribute(<span style="color:#A31515; "RecurringAppt", <span style="color:Blue; typeof(recurringApptType), Order=4)]
<span style="color:Blue; public <span style="color:Blue; object Item {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.itemField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.itemField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "Item");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=5)]
<span style="color:Blue; public trailerInfoType TrailerInfo {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.trailerInfoField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.trailerInfoField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "TrailerInfo");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=6)]
<span style="color:Blue; public <span style="color:Blue; string Comment {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.commentField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.commentField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "Comment");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string ShipperApptRequestID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.shipperApptRequestIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.shipperApptRequestIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ShipperApptRequestID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string ConsigneeApptID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.consigneeApptIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.consigneeApptIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ConsigneeApptID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string SchedulerID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.schedulerIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.schedulerIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "SchedulerID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string SchedulerCorpID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.schedulerCorpIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.schedulerCorpIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "SchedulerCorpID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string SchedulerCRID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.schedulerCRIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.schedulerCRIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "SchedulerCRID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string ShipperMultiStopID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.shipperMultiStopIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.shipperMultiStopIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ShipperMultiStopID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public <span style="color:Blue; string ConsigneeMultiStopID {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.consigneeMultiStopIDField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.consigneeMultiStopIDField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ConsigneeMultiStopID");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType=<span style="color:#A31515; "nonNegativeInteger")]
<span style="color:Blue; public <span style="color:Blue; string ShipperStopNumber {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.shipperStopNumberField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.shipperStopNumberField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ShipperStopNumber");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public apptTypeType ApptType {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.apptTypeField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.apptTypeField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "ApptType");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
<span style="color:Blue; public pickupOrDeliveryType PickupOrDelivery {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.pickupOrDeliveryField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.pickupOrDeliveryField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "PickupOrDelivery");
}
}

<span style="color:Gray; /// <span style="color:Gray; <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType=<span style="color:#A31515; "positiveInteger")]
<span style="color:Blue; public <span style="color:Blue; string PalletPositionCount {
<span style="color:Blue; get {
<span style="color:Blue; return <span style="color:Blue; this.palletPositionCountField;
}
<span style="color:Blue; set {
<span style="color:Blue; this.palletPositionCountField = value;
<span style="color:Blue; this.RaisePropertyChanged(<span style="color:#A31515; "PalletPositionCount");
}
}

<span style="color:Blue; public <span style="color:Blue; event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

<span style="color:Blue; protected <span style="color:Blue; void RaisePropertyChanged(<span style="color:Blue; string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = <span style="color:Blue; this.PropertyChanged;
<span style="color:Blue; if ((propertyChanged != <span style="color:Blue; null)) {
propertyChanged(<span style="color:Blue; this, <span style="color:Blue; new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[/code]

When deserializing from the follwoing code <br/>
from the follwoing code

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; object GetObjectFromXml(<span style="color:Blue; string strXml, System.Type objType)
{
XmlSerializer ser;
ser = <span style="color:Blue; new XmlSerializer(objType, <span style="color:#A31515; "http://idealliance.org/maildat/Specs/md091/mailxml80B/mailxml");
StringReader stringReader;
stringReader = <span style="color:Blue; new StringReader(strXml);
XmlTextReader xmlReader;
xmlReader = <span style="color:Blue; new XmlTextReader(stringReader);
<span style="color:Blue; object obj;
obj = ser.Deserialize(xmlReader);<span style="color:Green; //error line
xmlReader.Close();
stringReader.Close();
<span style="color:Blue; return obj;
}
i am getting error <DeliveryApptShellUpdateRequest xmlns=<span style="color:#A31515; http://idealliance.org/maildat/Specs/md091/mailxml80B/mailxml> was not expected.
[/code]



<hr class="sig Kamran Shahid Senior Software Engineer/Analyst (MCP,MCAD,MCSD.NET,MCTS,MCPD.net[web])

View the full article
 
Back
Top