Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Serialization BUG #72

Open
mathias13 opened this issue Feb 26, 2022 · 0 comments
Open

Serialization BUG #72

mathias13 opened this issue Feb 26, 2022 · 0 comments

Comments

@mathias13
Copy link

mathias13 commented Feb 26, 2022

I've got an application where i serilaize a struct with an array of Coordinates. Here is a simple example.

[Serializable]
public struct CoordStruct
{
    public Coordinate[] Coordinates;

    public CoordStruct(Coordinate[] coordinates)
    {
        Coordinates = coordinates;
    }
}

[Test]
public void TestSerialize()
{
    var coordStruct = new CoordStruct(new Coordinate[] { new Coordinate(1.0, 2.0, 3.0), new Coordinate(4.0, 5.0, 6.0) });
    var serializer = new System.Xml.Serialization.XmlSerializer(typeof(CoordStruct));
    var writer = new System.IO.StreamWriter(@"C:\Temp\Test.xml", false);
    serializer.Serialize(writer, coordStruct);
    writer.Close();
}

If i run this i get stuck in an infinite loop with a output like below.

<?xml version="1.0" encoding="utf-8"?>
<CoordStruct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Coordinates>
    <Coordinate>
      <X>1</X>
      <Y>2</Y>
      <Z>3</Z>
      <CoordinateValue>
        <X>1</X>
        <Y>2</Y>
        <Z>3</Z>
        <CoordinateValue>
          <X>1</X>
          <Y>2</Y>
          <Z>3</Z>
          <CoordinateValue>
            <X>1</X>
            <Y>2</Y>
            <Z>3</Z>
            <CoordinateValue>
              <X>1</X>
              <Y>2</Y>
              <Z>3</Z>

I have tested to change Coordinate.cs

Line 134

/// <summary>
/// Gets/Sets <other>Coordinate</other>s (x,y,z) values.
/// </summary>
[System.Xml.Serialization.XmlIgnore]
public Coordinate CoordinateValue
{
    get { return this; }
    set
    {
        X = value.X;
        Y = value.Y;
        Z = value.Z;
    }
}

Then i get this XML

<?xml version="1.0" encoding="utf-8"?>
<CoordStruct xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Coordinates>
    <Coordinate>
      <X>1</X>
      <Y>2</Y>
      <Z>3</Z>
    </Coordinate>
    <Coordinate>
      <X>4</X>
      <Y>5</Y>
      <Z>6</Z>
    </Coordinate>
  </Coordinates>
</CoordStruct>

The problem is that System.Xml.Serialization assembly is only available from v4.5 so it wont build with the rest of the frameworks.
I can create a pull request but i need som help how to approach this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant