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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:41:31+00:00 2026-05-26T13:41:31+00:00

I’m facing an annoying situation where my serialization/deserialization isn’t as expected. I want <OuterClass>

  • 0

I’m facing an annoying situation where my serialization/deserialization isn’t as expected.

I want

<OuterClass>
  <Assets>
      <Asset>Asset_A</Asset>
      <Asset>Asset_B</Asset>
  </Assets>
  ...
</OuterClass> 

but I’m getting

<OuterClass>
  <Assets>
    <Asset>
      <Asset>Asset_A</Asset>
    </Asset>
    <Asset>
      <Asset>Asset_B</Asset>
    </Asset>
  </Assets>
  ...
</OuterClass>

As you can see the Asset tag comes twice.

The code doing this is ..

public class OuterClass
{
    [DataMember(Name = "Assets", Order = 10)]
    public List<AssetClass> Assets { get; set; }
    ...
    [DataContract(Name = "Asset", Namespace = "")]
    public class AssetClass
    {
        [DataMember(Name = "Asset", Order = 10)]
        public string Asset { get; set; }
        ...
    } 
}

I know I’ve listed ‘Name=”Asset”‘ twice in the code too, but if I take out either of them, the framework adds it’s own name inside there still screwing it up. Somehow I suspect I need to change the structure of the code itself but not sure how to do that.

(edit)
I’m using the in-framework serialization/deserialization helpers. The code for that is (simplified):

public string ToXmlString(OuterClass AssetsWrapper)
{
    DataContractSerializer ser = new DataContractSerializer(typeof(OuterClass));            
    MemoryStream memStream = new MemoryStream();

    // Convert object -> stream -> byte[] -> string (whew!)
    ser.WriteObject(memStream, AssetsWrapper);
    byte[] AssetsWrapperByte = memStream.ToArray();
    return Encoding.UTF8.GetString(AssetsWrapperByte);
}
  • 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-26T13:41:31+00:00Added an answer on May 26, 2026 at 1:41 pm

    Ok, so I was able to resolve this .NET serialization weirdness by tinkering around with both the class markup as well as the actual serialization/deserialization code. Although the answers didn’t work as-is, thanks to Thomas and Munim for hints that led me down the right path after some experimentation.

    Serialization changes

    Replaced DataContractSerializer with XmlSerializer. This totally sucks because it’s a LOT (500%) slower 🙁 … (performance here)

    public string ToXmlString(OuterClass AssetsWrapper)
    {
        XmlSerializer ser = new XmlSerializer(typeof(OuterClass));            
        MemoryStream memStream = new MemoryStream();
    
        // Convert object -> stream -> byte[] -> string (whew!)
        ser.WriteObject(memStream, AssetsWrapper);
        byte[] AssetsWrapperByte = memStream.ToArray();
        return Encoding.UTF8.GetString(AssetsWrapperByte);
    }
    

    Class markup changes:

    public class OuterClass
    {
        [DataMember(Name = "Assets", Order = 10)]
        public ListAssetClass Assets { get; set; }
        ...
    
        //[DataContract(Name = "Asset123", Namespace = "")]
        public class ListAssetClass
        {
            [XmlElement(ElementName = "Asset")]
            public List<string> Assets { get; set; }
            ...
        }
    }
    

    now gives me

    <Assets>
      <Asset>Asset One</Asset>
      <Asset>Asset Two</Asset>
    </Assets>
    

    I’m surprised that the framework serialization/deserialization is so twisted and slow. I might have to look for an external library sometime.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
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
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is 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.