Hi,
My goal is to convert an object\class that contains some values, to a Byte Array.
I found some examples , but everything I try keeps throwing a System.Exeption.
[line]
The thread ‘’ (0x2) has exited with code 0 (0x0).
Using mainboard GHI Electronics FEZSpider version 1.0
#### Exception System.Exception - CLR_E_APPDOMAIN_MARSHAL_EXCEPTION (1) ####
#### Message:
#### Microsoft.SPOT.Reflection::Serialize [IP: 0000] ####
#### IC2_Ram_Spider.Program::ProgramStarted [IP: 0020] ####
#### IC2_Ram_Spider.Program::Main [IP: 0015] ####
A first chance exception of type ‘System.Exception’ occurred in Microsoft.SPOT.Native.dll
Microsoft.SPOT.Reflection::Serialize
IC2_Ram_Spider.Program::ProgramStarted
IC2_Ram_Spider.Program::Main
[line]
My code is straight from the forum.
namespace IC2_Ram_Spider
{
public partial class Program
{
public class MyClass
{
public int ii;
public float ff;
}
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
try
{
MyClass before = new MyClass();
before.ii = 1;
before.ff = 2;
byte[] SerializedData = Reflection.Serialize(before, typeof(MyClass));
MyClass after = (MyClass)Reflection.Deserialize(SerializedData, typeof(MyClass));
Debug.Print(after.ii.ToString());
Debug.Print(after.ff.ToString());
}
catch (Exception ex)
{
Debug.Print(ex.StackTrace.ToString());
}
finally
{
Debug.Print ("===") ;
}
}
}
}