A few weeks ago, I upgraded an XML server of ours to .NET 2.0. All went
fine. Then last week, I decided to remove all obsolete calls from the app
and sign each project in the solution in the .NET 2 way so that the app
compiled with no warnings. This built fine but we noticed that server was
deserializing one
of our XML messages incorrectly. I confirmed via source control
that neither the schemas themselves nor the classes representing the
messages had been altered but the problem continued.
After some investigation, I found I could I could actively switch this bug
on and off in debug mode by switching between the .NET 1.1 and .NET 2.0 ways
of signing the assembly which contains the serialization code. By this I mean.
..NET 1.1 = Opening assemblyinfo.cs and identifying a key with [assembly:
AssemblyKeyFile(@"somekey)]
..NET 2.0 - Removing this line of code from assemblyinfo.cs and setting
the key to sign the project with in the project proerties dialog.
If I use the .NET 1.1 method, the XML is serialized correctly in debug
build but not in release build. If I use the .NET 2.0 method, the XMl is
serialized wrongly in both builds. I have now reverted all code back to the
original .NET 2.0 build but the problem still persists - debug build is fine
but release build continues to deserialize incorrectly, so I'm completely
lost now. I have pasted below highlights of the xml message as it should
appear, the xml message as it currently appears, the schema I'm working with
and the class which represents the elements being serialized.
Any ideas?
Dan Maharry
MSDN ID: 210068425
---
Correct XML.
<?xml version="1.0" encoding="utf-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<greeting>
....
</greeting>
</epp>
---
Incorrect XML
<?xml version="1.0" encoding="utf-8"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<hello d2p1:type="greetingType"
xmlns:d2p1="http://www.w3.org/2001/XMLSchema-instance">
....
</hello>
</epp>
---
Schema (relevant pieces)
<?xml version="1.0" encoding="UTF-8" ?>
<schema targetNamespace="urn:ietf:params:xml:ns:epp-1.0"
xmlns:epp="urn:ietf:params:xml:ns:epp-1.0"
xmlns:eppcom="urn:ietf:params:xml:ns:eppcom-1.0"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<!--
Import common element types.
-->
<import namespace="urn:ietf:params:xml:ns:eppcom-1.0"
schemaLocation="eppcom-1.0.xsd" />
<annotation>
<documentation>
Extensible Provisioning Protocol v1.0 schema.
</documentation>
</annotation>
<element name="epp" type="epp:eppType" />
<complexType name="eppType">
<choice>
<element name="greeting" type="epp:greetingType" />
<element name="hello" />
<element name="command" type="epp:commandType" />
<element name="response" type="epp:responseType" />
<element name="extension" type="epp:extAnyType" />
</choice>
</complexType>
<complexType name="greetingType">
<sequence>
<element name="svID" type="epp:sIDType" />
<element name="svDate" type="dateTime" />
<element name="svcMenu" type="epp:svcMenuType" />
<element name="dcp" type="epp:dcpType" />
</sequence>
</complexType>
---
C# class generated by xsd.exe
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="urn:ietf:params:xml:ns:epp-1.0", TypeName="eppType")]
[System.Xml.Serialization.XmlRootAttribute("epp",
Namespace="urn:ietf:params:xml:ns:epp-1.0", IsNullable=false)]
public class EppType {
private object item;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("hell o",
typeof(object))]
[System.Xml.Serialization.XmlElementAttribute("resp onse",
typeof(ResponseType))]
[System.Xml.Serialization.XmlElementAttribute("gree ting",
typeof(GreetingType))]
[System.Xml.Serialization.XmlElementAttribute("exte nsion",
typeof(ExtAnyType))]
[System.Xml.Serialization.XmlElementAttribute("comm and",
typeof(EppCommandType))]
public object Item {
get {
return this.item;
}
set {
this.item = value;
}
}
}