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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:57:40+00:00 2026-05-13T17:57:40+00:00

A LinkedList can’t be serialized using XmlSerializer. Now, how to however save/retrieve data from

  • 0

A LinkedList can’t be serialized using XmlSerializer.

Now, how to however save/retrieve data from a serialized objet LinkedList. Should I implement custom serialization?

What I tried to do:

using System.Xml.Serialization;

[Serializable()]
public class TestClass
{
    private int _Id;
    private string _Name;
    private int _Age;
    private LinkedList<int> _linkedList = new LinkedList<int>();

    public string Name {
        get { return _Name; }
        set { _Name = value; }
    }
    
    public string Age {
        get { return _Age; }
        set { _Age = value; }
    }
    
    [XmlArray()]
    public List<int> MyLinkedList {
        get { return new List<int>(_linkedList); }
        set { _linkedList = new LinkedList<int>(value); }
    }
}

What I’ve obtained(addind name, age and some items in the mylinkedlist):

<?xml version="1.0"?>
<TestClass 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Name>testName</Name>
  <Age>10</Age>
  <MyLinkedList />
</TestClass>

So, the items in the linked list hadn’t been serialized… 🙁

  • 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-13T17:57:41+00:00Added an answer on May 13, 2026 at 5:57 pm

    One possibility would be the creation of a serializable collection that contains the same objects as the linked list. E.g. (untested):

    LinkedList<Foo> ll = PopulateLinkedList();
    List<Foo> list = new List<Foo>(ll);
    

    Then serialize list instead. This isn’t going to create a lot of overhead if Foo is a reference type, and you don’t care about the fact that insertions/deletions are now more expensive b/c you’re only using the List<T> to hold references to the data for serialization and deserialization purposes. When you pull it out of the serialized stream, you can just turn it back into a LinkedList<T> to get all those advantages you were using a linked list for in the first place.


    Here’s a little console app I just whipped up to demonstrate. I did it in VS2008, but I don’t think I used anything surprising– just the array initialization syntax to save some vertical space.

    Sample Code:

    [Serializable]
    public class MyClass
    {
        private string name;
        private int age;
        private LinkedList<int> linkedList = new LinkedList<int>();
    
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    
        public int Age
        {
            get { return age; }
            set { age = value; }
        }
    
        [XmlArray]
        public List<int> MyLinkedList
        {
            get { return new List<int>(linkedList); }
            set { linkedList = new LinkedList<int>(value); }
        }
    }
    

    And the main application code:

    class Program
    {
        static void Main(string[] args)
        {
            MyClass c = new MyClass();
    
            c.Age = 42;
            c.Name = "MyName";
            c.MyLinkedList = new List<int>() { 1, 4, 9 }; // Your property impl requires this be set all at once, not one element at a time via the property.
    
            XmlSerializer s = new XmlSerializer(typeof(MyClass));
            StringWriter outStream = new StringWriter();
            s.Serialize(outStream, c);
    
            Console.Write(outStream.ToString());
    
            return;
        }
    }
    

    This kicks the following out to the console:

    <?xml version="1.0" encoding="utf-16"?>
    <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <Name>MyName</Name>
      <Age>42</Age>
      <MyLinkedList>
        <int>1</int>
        <int>4</int>
        <int>9</int>
      </MyLinkedList>
    </MyClass>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 351k
  • Answers 351k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Provide your data in JSON-P format instead. May 14, 2026 at 7:18 am
  • Editorial Team
    Editorial Team added an answer Why not use the click event? It's how the client… May 14, 2026 at 7:18 am
  • Editorial Team
    Editorial Team added an answer If you use a socket (and practically building your own… May 14, 2026 at 7:18 am

Related Questions

I encountered a simple problem: Exchange two nodes in a LinkedList ( .NET 2
I have a LinkedList, where Entry has a member called id. I want to
I need a method that takes a linkedlist as a parameter and return true
I need to use a LinkedList to add cells of a prison with the
Perhaps someone can point me in the correct direction, because I'm completely stumped on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.