Serialization on Raptor in 4.3

I’m trying to figure out how to use serialization but get an exception I can’t figure out. As far as I can tell, my test program is just like the examples I’ve found on the forum.

using System;
using Microsoft.SPOT;

namespace SerializeTest
{
    public class Program
    {

        public struct DepthTable
        {
            public float depth;
            public float PV;
            public TimeSpan parkTime;
        }

        [Serializable]
        public class serMission
        {
            public DepthTable[] descendTable = new DepthTable[1];
            public DepthTable[] ascendTable = new DepthTable[3];

            public serMission(float depth, float PV, TimeSpan parkTime)
            {
                descendTable[0].depth = depth;
                descendTable[0].PV = PV;
                descendTable[0].parkTime = parkTime;

                ascendTable[0].depth = depth - 2;
                ascendTable[0].PV = PV - (float).01;
                ascendTable[0].parkTime = new TimeSpan(0, 0, 0, 0);         //days, hours, minutes, seconds

                ascendTable[1].depth = depth - 4;
                ascendTable[1].PV = PV - (float).02;
                ascendTable[1].parkTime = new TimeSpan(0, 0, 0, 0);         //days, hours, minutes, seconds

                ascendTable[2].depth = depth - 6;
                ascendTable[2].PV = PV - (float)0.03;
                ascendTable[2].parkTime = new TimeSpan(0, 0, 0, 0);         //days, hours, minutes, seconds
            }
        }
        public static void Main()
        {
            Debug.Print("Program Started");

            TimeSpan ts = new TimeSpan(0, 0, 3, 0);

            serMission inMission = new serMission((float)15.0, (float)0.1, ts);
        
            byte[] buffer = Reflection.Serialize(inMission, typeof(serMission));

            serMission outMission = (serMission)Reflection.Deserialize(buffer, typeof(serMission));

            Debug.Print("Num of descend table elements = " + outMission.descendTable.Length.ToString());

        }
    }
}

Here’s the exception

Program Started
#### Exception System.Exception - CLR_E_APPDOMAIN_MARSHAL_EXCEPTION (1) ####
#### Message:
#### Microsoft.SPOT.Reflection::Serialize [IP: 0000] ####
#### SerializeTest.Program::Main [IP: 002d] ####
A first chance exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Native.dll
An unhandled exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Native.dll

Thanks for the help

Amazing how I alway get a lot smarter right after I post a question on the Forum.

If anyone else needs to know, you need to also add a [Serializable] ahead of the structure definition like this


        public struct DepthTable
        {
            public float depth;
            public float PV;
            public TimeSpan parkTime;
        }
1 Like