Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / April 2006

Tip: Looking for answers? Try searching our database.

XmlSerializer produces different results in debug and release buil

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Maharry - 26 Apr 2006 13:01 GMT
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(Namespace="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("hello",
typeof(object))]
       [System.Xml.Serialization.XmlElementAttribute("response",
typeof(ResponseType))]
       [System.Xml.Serialization.XmlElementAttribute("greeting",
typeof(GreetingType))]
       [System.Xml.Serialization.XmlElementAttribute("extension",
typeof(ExtAnyType))]
       [System.Xml.Serialization.XmlElementAttribute("command",
typeof(EppCommandType))]
       public object Item {
           get {
               return this.item;
           }
           set {
               this.item = value;
           }
       }
   }
Dan Maharry - 26 Apr 2006 17:10 GMT
For reference, I've also compiled a small code sample written directly in
.NET 2.0 that demonstrates the same issue although in this case, the
serialization error seems to occur in both debug and release builds. Please
email me if you would like to take a look at the code.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.