LinkedList of custom types throws a format exception

Mar 11, 2014 at 10:11 PM
Edited Mar 11, 2014 at 10:15 PM
Hello, i've got a question concerning the code below. I've added a class testpoint with properties Id, X and Y. I put two instances of this class on a linkedlist. The class with the linkedlist is then serialized to file. When deserializing from file YaxLib throws a Format exception. It turns out that the content of the TestPoint class is all written into one string and of course cannot be parsed to a double. Maybe you got a thought about this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAXLib;
using DemoApplication.SampleClasses;

namespace YAXLibTests.SampleClasses
{
    [ShowInDemoApplication]
    [YAXSerializableType(FieldsToSerialize = YAXSerializationFields.AttributedFieldsOnly)]
    public class SampleClassForTestPoint
    {
        [YAXSerializableField]
        private LinkedList<TestPoint> _testPoints;
        /// <summary>
        /// Initializes a new instance of the SampleClassForTestPoint class.
        /// </summary>

        public SampleClassForTestPoint()
        {
            _testPoints = new LinkedList<TestPoint>();
            _testPoints.AddLast(new TestPoint() { Id = 0, X = 100, Y = 100 });
            _testPoints.AddLast(new TestPoint() { Id = 1, X = -100, Y = 150 });
        }

        public static SampleClassForTestPoint GetSampleInstance()
        {

            return new SampleClassForTestPoint();
        }


        public override string ToString()
        {
            return GeneralToStringProvider.GeneralToString(this);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DemoApplication.SampleClasses
{
    public class TestPoint
    {
        private int _id;
        private double _x;
        private double _y;
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        public double X
        {
            get { return _x; }
            set { _x = value; }
        }
        public double Y
        {
            get { return _y; }
            set { _y = value; }
        }

    }
}
Mar 15, 2014 at 12:02 AM
Edited Mar 15, 2014 at 12:08 AM
Ok, I figured it out with the help of the comments on your codeproject article. Apparently there is a bug in the code concerning properties that are one letter long, i.e. X or Y. If this is the case the formatting gets a little messed up.
B.O.B suggests the error is in stringutils file, function SplitPathNamespaceSafe (code lines 326 to 357).
if (lastStart < temp.Length - 1)

should be
if (lastStart < temp.Length) // Drop the - 1
or
if (lastStart <= temp.Length - 1) 
Coordinator
Mar 15, 2014 at 2:38 PM
Hello.
I fixed the code after B.O.B's comment, and it'll be present in 2.13, which is not out yet.
Meanwhile you can build the latest source code and use it:
https://yaxlib.codeplex.com/SourceControl/latest

I added your sample above above to the set of test classes of the library, and added unit tests to make sure the desired output is produced. Thanks for that.
https://yaxlib.codeplex.com/SourceControl/latest#YAXLibTests/SampleClasses/SingleLetterPropertyNames.cs