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

  • SEARCH
  • Home
  • 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 7565957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:17:24+00:00 2026-05-30T14:17:24+00:00

I’m trying to deserialize an XML stream into an object. It works perfectly for

  • 0

I’m trying to deserialize an XML stream into an object. It works perfectly for all but one field and I can’t figure out what is wrong with that field. To make sure I know what I’m dealing with, I’ve coded the XML string directly.

[DataContract(Name = "auth")]
public class Authorization
{
    [DataMember(Name = "status")]
    public string Status { get; set; }
    [DataMember(Name = "user_name")]
    public string UserName { get; set; }
    [DataMember(Name = "person_pk")]
    public string PersonID { get; set; }
}

StringBuilder sb = new StringBuilder();
sb.Append("<auth xmlns=\"http://schemas.datacontract.org/2004/07/Veracross\">");
sb.Append("<status>success</status>");
sb.Append("<person_pk>2516</person_pk>");
sb.Append("<user_name>scohen</user_name>");
sb.Append("</auth>");

string fixedXMLData = sb.ToString();

DataContractSerializer serializer = new DataContractSerializer(typeof(Authorization));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(fixedXMLData));
Authorization Auth = (Authorization)serializer.ReadObject(stream);

When I test the Auth object after execution I find that Status and UserName are properly populated. PersonID is null. I’ve tried changing the field names in the XML string, reordering the fields, changing the content of the person_pk field, etc. Nothing makes it work.

Now here’s where it gets weird – If I change "person_pk" to "test" everywhere, it works fine and I get the correct value for PersonID. However, if I swap "person_pk" for "person" or "pk" it still doesn’t work? In reality, I’m getting this XML string from a RESTful service and have no control over the naming of the fields. The field is named "person_pk", I just can’t figure out why it won’t properly deserialize.

Any idea?

Thanks

  • 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-30T14:17:25+00:00Added an answer on May 30, 2026 at 2:17 pm

    Change the order of fields in XML file so that person_pk comes before status:

    sb.Append("<auth xmlns=\"http://schemas.datacontract.org/2004/07/Veracross\">");
    sb.Append("<person_pk>2516</person_pk>");
    sb.Append("<status>success</status>");
    sb.Append("<user_name>scohen</user_name>");
    sb.Append("</auth>");
    

    DataSerializer considers the fields order too.

    UPDATE:
    You may be interested in this discussion:
    Ignore field order in DataContractSerializer

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.