Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3349408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:39:39+00:00 2026-05-18T01:39:39+00:00

I have the following class: /// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute(System.Xml, 4.0.30319.1)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(code)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=urn:eu.emsa.ssn)] public

  • 0

I have the following class:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:eu.emsa.ssn")]
public partial class SSN_ReceiptType {

    private Header1Type headerField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public Header1Type Header {
        get {
            return this.headerField;
        }
        set {
            this.headerField = value;
        }
    }
}

And the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <SSN_Receipt xmlns="urn:eu.emsa.ssn">
        <Header StatusMessage="SomethingSomething" StatusCode="Blabla" SSNRefId="N/A" MSRefId="2674762" Version="2.0" To="NCANOHAU1" SentAt="2010-11-12T14:48:44Z" From="SSN"/>
    </SSN_Receipt>

And I use this typed method to deserialize (by calling Deserialize<SSN_ReceiptType>(xmlGoesHere)):

    /// <summary>
    /// Deserialize xml string to object of type T
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="xml"></param>
    /// <returns></returns>
    public static T Deserialize<T>(string xml)
    {
        try
        {

            // Create serializer
            var xs = new XmlSerializer(typeof(T));

            // Deserialize
            T t = (T)xs.Deserialize(new StringReader(xml));

            return t;
        }
        catch (Exception e)
        {
            log.Error(string.Format("Unable to deserialize XML: {0}", xml), e);

            return default(T);
        }
    }

Now here’s the kicker. This used to work. But recently we received a new version of the XSD used to generate the classes, and after generating the new code (which is unchanged for this class, and seen above) I receive the following exception when trying to deserialize:

System.SystemException: “There is an error in XML document (1, 57)”

And furthermore:

System.InnerException: <SSN_Receipt xmlns=’urn:eu.emsa.ssn’> was not expected.

What the hell? :S I tried adding an XmlRootAttribute specifying “SSN_Receipt”, that did not help one bit. Anyone know what’s going on?

Update: relevant sections from the XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:ssn="urn:eu.emsa.ssn" 
    attributeFormDefault="unqualified" 
    elementFormDefault="qualified" 
    targetNamespace="urn:eu.emsa.ssn">
[...]
<xsd:element name="SSN_Receipt" type="ssn:SSN_ReceiptType"/>
[...]
<xsd:complexType name="SSN_ReceiptType">
    <xsd:annotation>
        <xsd:documentation xml:lang="en"/>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element name="Header" type="ssn:Header1Type"/>
    </xsd:sequence>
</xsd:complexType>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:39:40+00:00Added an answer on May 18, 2026 at 1:39 am

    For future reference for other poor souls, here is the solution I came up with.

    As mentioned in my question, my classes are generated from an XSD. I tested the previous version of our classes, and they work just fine still. Additionally, SOAP services which utilize the same classes also works. Inspecting the trace log, I can’t see anything revealing in particular.

    But I found a concrete solution. I added the following attribute to my class:

    [System.Xml.Serialization.XmlRoot(Namespace = "urn:eu.emsa.ssn", 
                                      ElementName = "SSN_Receipt")]
    

    Now, I don’t want to litter my generated classes with custom code, so I added a partial class:

    [System.Xml.Serialization.XmlRoot(Namespace = "urn:eu.emsa.ssn", 
                                      ElementName = "SSN_Receipt")]
    public partial class SSN_ReceiptType {}
    

    This fixes my problem completely. But I still don’t understand why this broke in the first place.

    If anyone can come up with a good testable answer to why it broke, I will make that the proper answer.

    Thank you for your time guys! This has been an educational experience, to some extent 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class public class Car { public Name {get; set;} }
I have the following class which uses BinaryReader internally and implements IDisposable. class DisposableClass
I have the following class: public abstract class AbstractParent { static String method() {
I have the following class [XmlRoot(ElementName= webSites)] //No capital w at the beginning public
I have the following class structure FlowerDAO with the fields (mapped using Hibernate): id
I have the following class in my C# .NET 3.5 win forms app: class
I have the following class objects: public class VacancyCategory { public int ID {
Say I have the following class MyComponent : IMyComponent { public MyComponent(int start_at) {...}
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
Let's have the following class hierarchy: public class ParentClass implements SomeInterface { } public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.