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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:14:19+00:00 2026-06-17T16:14:19+00:00

I’m writing a Windows Store App and I need to store some data in

  • 0

I’m writing a Windows Store App and I need to store some data in Roaming Storage; for that I needed to serialize/deserialize some data. My serializer/deserializer functions are as below:

public string Serialize()
    {
        try
        {
            StringWriter sw = new StringWriter();

            XmlSerializer xs = new XmlSerializer(typeof(RssData));
            xs.Serialize(sw, this);


            return sw.ToString();
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex);
            return String.Empty;
        }
    }

    public void Deserialize(string serialized)
    {
        try
        {
            XmlSerializer xs = new XmlSerializer(typeof(RssData));
            XmlReader xr = XmlReader.Create(new StringReader(serialized));
            RssData rd = xs.Deserialize(xr) as RssData;
            this.categoryList = rd.categoryList;
            this.defaultCategory = rd.defaultCategory;
        }
        catch(Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex);
        }
    }

In summary, RssData has a list of RssCategory, and each RssCategory has a RssFeed. There is no problem with serialization and the following string is an example that I’ve produced using the Serialize function above:

<?xml version="1.0" encoding="utf-16"?>
<RssData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CategoryList>
    <RssCategory>
      <Name>No Category</Name>
      <RssList>
        <RssFeed>
          <Title>HABERTURK.COM</Title>
          <Url>http://www.haberturk.com/rss</Url>
          <Image>http://www.haberturk.com/images/htklogo2.jpg</Image>
          <Subtitle>HABERTÜRK - Türkiye'nin En Büyük İnternet Gazetesi</Subtitle>
        </RssFeed>
      </RssList>
    </RssCategory>
  </CategoryList>
</RssData>

However, when I Deserialize this XML, the resulting RssData has a CategoryList with 2 RssCategories, one is a RssCategory named “No Category” with an empty RssList, the other one is the correct one as defined in the XML; i.e. “No Category” with one RssFeed.

Is it a problem with my code or is XmlSerializer bugged?

  • 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-06-17T16:14:19+00:00Added an answer on June 17, 2026 at 4:14 pm

    Ok it seems that XmlSerializer first constructs the object using its no-parameter constructor then adds each item in the XML to the appropriate list. Thus if the constructor adds some items to that list, deserializing will result in a list that includes any item added in the constructor.

    Edit: So if you serialize/deserialize a class that has a property of type Array/List/Container etc, in the no-parameter constructor you have to initialize it, but do not add anything to it.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I am writing an app with both english and french support. The app requests
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.