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 7692749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:55:28+00:00 2026-05-31T20:55:28+00:00

When i am doing Deserialize of xml i am getting There is an error

  • 0

When i am doing Deserialize of xml i am getting “There is an error in XML document (1, 41).” . Can anyone tell me about what is the issue is all about.

 public static T DeserializeFromXml<T>(string xml)
        {
            T result;
            XmlSerializer ser = new XmlSerializer(typeof(T));
            using (TextReader tr = new StringReader(xml))
            {
                result = (T)ser.Deserialize(tr);
            }
            return result;
        }

I use this function to do it.

<?xml version='1.0' encoding='utf-16'?>
<Message>
<FirstName>Hunt</FirstName>
<LastName>DAvid</LastName>
</Message>
  • 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-31T20:55:29+00:00Added an answer on May 31, 2026 at 8:55 pm

    Ensure your Message class looks like below:

    [Serializable, XmlRoot("Message")]
    public class Message
    {
        public string FirstName { get; set; }
    
        public string LastName { get; set; }
    }
    

    This works for me fine:

    string xml = File.ReadAllText("c:\\Message.xml");
    var result = DeserializeFromXml<Message>(xml);
    

    MSDN, XmlRoot.ElementName:

    The name of the XML root element that is generated and recognized in
    an XML-document instance. The default is the name of the serialized
    class
    .

    So it might be your class name is not Message and this is why deserializer was not able find it using default behaviour.

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

Sidebar

Related Questions

When doing TDD , how to tell that's enough tests for this class /
The HR-XML 3.0 spec provides WSDL's to generate their entities. I'm trying to deserialize
I'm wrestling to deserialize the following XML: <?xml version=1.0 encoding=utf-8 ?> <conf name=settings> <item
I have a XML document with a node like this. <channel id=3102 platform =
I am trying to deserialize some xml into an IList, but I am having
I have some XML that I am trying to deserialize the xml below. <?xml
There's already a lot of blog posts out there about being able to hook
I have the following 2 functions: public static string Serialize(object obj) { DataContractSerializer serializer
Can't understand what I am doing wrong, the result set is empty. My code:
I can serialize a List<Video> in my servlet on GAE, but I can't deserialize

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.