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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:11:23+00:00 2026-06-13T04:11:23+00:00

I’ve read Shawn Harvgreave’s blog entry about automatic serialization and the MSDN article on

  • 0

I’ve read Shawn Harvgreave’s blog entry about automatic serialization and the MSDN article on an overview of the content pipeline, but I couldn’t find a list of the types supported.

Quoting MSDN:

Starting with XNA Game Studio 3.1, the serialization of custom data to
the .XNB format is done automatically for simple types that do not
have an existing content type writer.

I haven’t had problems with this until I tried to use a Queue from System.Collections.Generic which I’m guessing isn’t supported by the automatic serialization.

So, is there a list of types supported by this? And if it isn’t supported, will I need to write my own ContentTypeWriter and ContentTypeReader?

  • 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-13T04:11:25+00:00Added an answer on June 13, 2026 at 4:11 am

    Providing a complete list of compatible types is tricky – because the serializer tries to be compatible with custom types it has never seen before. So any list of compatible classes cannot be exhaustive. As Shawn’s blog post says:

    By default it will serialize all the public fields and properties of your type (assuming they are not read-only).

    But let’s talk about collection classes. By the above rule, collection classes won’t be serialized correctly (when using reflection), because their collection of objects is not a public property (also, indexers aren’t supported).

    It’s interesting to point out why automatically serializing a collection like this isn’t a built-in feature. A collection usually implements IEnumerable<T> (like Queue<T> does), which could be serialized. But that’s read-only. There’s no standard interface like IEnumerable for writing to collections. So there’s no way to automatically deserialize them!

    Fortunately, XNA provides custom readers/writers for the following generic collection types:

    • Arrays
    • List<T>
    • Dictionary<TKey, TValue>

    The serializer automatically uses custom readers/writers when they are available. So if you want it to handle a collection class (like Queue<T>), then you must create your own ContentTypeWriter and ContentTypeReader for it. Fortunately this isn’t too hard – see below for an untested implementation.

    For a full list of built-in types, see the XNB Format specification. Again this just covers the built-in types. Other types can be supported through reflection or by providing custom reader/writer pairs.


    class QueueReader<T> : ContentTypeReader<Queue<T>>
    {
        public override bool CanDeserializeIntoExistingObject { get { return true; } }
    
        protected override Queue<T> Read(ContentReader input, Queue<T> existingInstance)
        {
            int count = input.ReadInt32();
            Queue<T> queue = existingInstance ?? new Queue<T>(count);
            for(int i = 0; i < count; i++)
                queue.Enqueue(input.ReadObject<T>());
            return queue;
        }
    }
    
    [ContentTypeWriter]
    class QueueWriter<T> : ContentTypeWriter<Queue<T>>
    {
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return typeof(QueueReader<T>).AssemblyQualifiedName;
        }
    
        public override bool CanDeserializeIntoExistingObject { get { return true; } }
    
        protected override void Write(ContentWriter output, Queue<T> value)
        {
            output.Write(value.Count);
            foreach(var item in value)
                output.WriteObject<T>(item);
        }
    }
    

    Note that my implementation of GetRuntimeReader here doesn’t handle cases where targetPlatform isn’t Windows. And you’ll need to put these in the right assemblies so you don’t get dependency issues.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when 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.