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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:06:32+00:00 2026-05-25T16:06:32+00:00

I am trying to serialize by following code var data = argsPerCall.ToArray(); var knownTypes

  • 0

I am trying to serialize by following code

var data = argsPerCall.ToArray();
var knownTypes = new[] { typeof(int), typeof(int),  
                         typeof(string), typeof(McPosition)};

var serializer = new XmlSerializer(data.GetType(), knownTypes);
// Writing the file requires a TextWriter.
var myStreamWriter = new StreamWriter(filename);
serializer.Serialize(myStreamWriter, data);
myStreamWriter.Close();

I am having an issue with McPosition type.

For following input

5 , 1, "R251" , {1,2,3}

I am getting following serialization

<ArrayOfAnyType>
    <anyType xsi:type="xsd:int">5</anyType>
    <anyType xsi:type="xsd:int">1</anyType>
    <anyType xsi:type="xsd:string">R251</anyType>
    <anyType xsi:type="McPosition" />
  </ArrayOfAnyType>

Any idea why it wasnt serialized correctly ?

EDIT:

public struct McPosition : IComparable<McPosition> {
    private readonly int _station;
    private readonly int _slot;
    private readonly int _subslot;


    public static McPosition Empty = new McPosition(-1, -1, -1);


    public McPosition(int station, int slot, int subslot) {
      _station = station;
      _slot    = slot;
      _subslot = subslot;
    }

etc….

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-25T16:06:33+00:00Added an answer on May 25, 2026 at 4:06 pm

    To be serializeable via XmlSerializer, each property on a type must have a public getter and setter (and not be marked [XmlIgnore] nor have a ShouldSerialize*() that returns false, etc). Public fields are also serialized (as long as they aren’t readonly), but exposing fields is even less desirable. XmlSerializer never looks at private members.

    I’m guessing (edit: now confirmed by the updated question) that McPosition is an immutable vector, without public setters. That won’t work. Options:

    • implement IXmlSerializable (not overly nice, to be honest)
    • add public setters to McPosition
    • use a separate DTO that is fully mutable
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to serialize an object and the following SerializationException is thrown: Type 'System.Linq.Enumerable+d__71`1[[System.String,
I have the following code in which I'm trying to serialize a list to
I'm trying to serialize a Type object in the following way: Type myType =
I'm trying to use the following code to log users in: $(form).submit(function(event) { $.ajax({
I am trying to use this piece of code to serialize a form AND
I am trying to serialize a Dictionary to JSON, and get the following exception:
I have the following code: XmlSerializer SerializeObj = new XmlSerializer(dirs.GetType()); TextWriter WriteFileStream = new
I have the following code: public class DeserializeAndCompare { public static List<string> IntoXML() {
I'm trying to figure out how to serialize the following class into XML (in
I have been trying to serialize some json data in Silverlight. I am using

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.