Notification

Icon
Error

Sync data between MF_device / WebServer
Cedric
#1 Posted : Tuesday, February 07, 2012 9:56:59 AM(UTC)
Rank: Newbie

Joined: 2/6/2012(UTC)
Posts: 0

Hi Folks,


In order to sync data between a MF device (MF 4.1) and dotnet webServer (HttpListener / dotnet3.5), I have to implemented the same serializaton process on each frameworks (MF and dotNet). 


I read on this post (http://www.netmf.com/for....aspx?g=posts&t=2232) that Zach was able to use the v4.1 Microsoft.SPOT.Debugger.BinaryFormatter in Microsoft.SPOT.Debugger.dll in a PC app to serialize/deserialize data to/from a v4.1 Net MF device. 


I have tried to do the same, but although Microsoft.SPOT.Debugger.dll is well referenced into my dotnet project, when i compile it i got the following error:


Unable to resolve the referenced assembly "Microsoft.SPOT.Debugger, Version=4.1.2821.0 ...


Any ideas would be appreciated.


Thx in advance for your help.


Cedric


Below my Serialize method implement on the webServer :


public static byte[] MFSerializeObject(DTO dto)
{
Microsoft.SPOT.Debugger.BinaryFormatter bf = new Microsoft.SPOT.Debugger.BinaryFormatter();
return bf.Serialize(dto.GetType(), dto);

}
Zach Libby
#2 Posted : Tuesday, February 07, 2012 12:56:30 PM(UTC)
Zach Libby

Rank: Tinkerer

Joined: 2/5/2010(UTC)
Posts: 243

Was thanked: 8 time(s) in 8 post(s)
Hello Cedric,

I believe the Microsoft.SPOT.Debugger.dll from v4.1 was compiled with dotnet4.0. So you will have to use dotnet4.0 in order to use the debugger dll. Use ildasm to confirm which framework the debugger DLL was compiled with.

Thanks,
Zach
Cedric
#3 Posted : Wednesday, February 08, 2012 12:47:43 PM(UTC)
Rank: Newbie

Joined: 2/6/2012(UTC)
Posts: 0

Hello Zach,

Nice its work, like you said the Microsoft.SPOT.Debugger.dll from v4.1 was compiled with dotnet4.0. So i have to use dotnet4.0 in order to use the debugger dll.

 

Now i able to use the method BinaryFormatter.serialize to serialize my object (from server side) but the method Reflection.Deserialize (from client MF device) seems to not support this serialization.

 

Do you know what classes and methods must be used to exchange data with serialisation bewteen MF application and .net application.

 

Thanks in advance for your help.

 

Cedric

 

Below you will find some pieces of code to explain how i try to implement the serialization/deserialization.

 

DTO class : 
    [Serializable]
    public class PersonDTO : DTO
    {

        // Field
        public string FirstName  {get; set;}
        public string LastName  {get; set;}

        // Constructor
        public PersonDTO()
        { }
       
        public PersonDTO(string firstName, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
        } 
    }


 

Server side (serialization) - .net app:

...
BinaryFormatter bf = new BinaryFormatter();
PersonDTO person = new PersonDTO("Cedric", "CONTE");
byte[] buffer = bf.Serialize(person.GetType(), person);

... 

 

Client side (deserialization) - MF app

...

Stream respStream = resp.GetResponseStream();
PersonDTO person = null;
byte[] tabPerson = new byte[(int)respStream.Length];
respStream.Read(tabPerson, 0, (int)respStream.Length);
person = (PersonDTO)Reflection.Deserialize(tabPerson, person.GetType());

...


 
Zach Libby
#4 Posted : Wednesday, February 08, 2012 4:05:06 PM(UTC)
Zach Libby

Rank: Tinkerer

Joined: 2/5/2010(UTC)
Posts: 243

Was thanked: 8 time(s) in 8 post(s)
You probably just need to use fields instead of properties for the Micro Framework. Also I am not 100% sure that inheritence is supported for the serializer. Try the following (you can still use get/set for assignment if needed):

[Serializable]
public class PersonDTO : DTO
{
// Field
public readonly string m_firstName;
public readonly string m_lastName;

// Constructor
public PersonDTO() { }
public PersonDTO(string firstName, string lastName)
{
m_firstName = firstName;
m_lastName = lastName;
}
}

thanks,
zach
Cedric
#5 Posted : Thursday, February 09, 2012 3:58:50 AM(UTC)
Rank: Newbie

Joined: 2/6/2012(UTC)
Posts: 0

Thanks zach,

 

I have followed your advice and change my DTO class with fields and without inheritence but it' still doesnt work.

Actually i have notice the following :

 

When I serialize this object with BinaryFormatter, I get a byte[13] // {6, 67, 101, 100, 114, 105, 99, 5, 67, 79, 78,84, 69} 

BinaryFormatter bf = new BinaryFormatter();
PersonDTO person = new PersonDTO("Cedric", "CONTE");
byte[] buffer = bf.Serialize(person.GetType(), person);

 

When I serialize this object with Reflection.Serialize, I get a byte[18] // {166, 41, 160, 175, 129, 144, 217, 89, 28, 193, 80, 211, 211,149, 17, 64}

PersonDTO person = new PersonDTO("Cedric", "CONTE");
byte[] buffer = Reflection.Serialize(person, person.GetType());

 

The Serialization are differents so i guess we cannot have Serialize/Deserialize compatibility between BinaryFormatter and Reflection.

 

Below the DTO used :


[Serializable]
public class PersonDTO
{
// Field
public readonly string m_firstName;
public readonly string m_lastName;

// Constructor
public PersonDTO() { }
public PersonDTO(string firstName, string lastName)
{
m_firstName = firstName;
m_lastName = lastName;
}
}

Am I doing something wrong ? Any ideas about it ? 

Thanks for your help,

 

Cedric
Zach Libby
#6 Posted : Thursday, February 09, 2012 12:28:46 PM(UTC)
Zach Libby

Rank: Tinkerer

Joined: 2/5/2010(UTC)
Posts: 243

Was thanked: 8 time(s) in 8 post(s)
Sorry, I must have misunderstood what you were attempting. Our binary serializer/deserializer is not compatible with any other serializer. I was under the impression you were using the same serializer on both ends. That is the only way it would work. BTW, our strings are always converted to UTF8 for serialization, which is probably why there is a difference in size.

Thanks,
Zach
Cedric
#7 Posted : Friday, February 10, 2012 3:16:49 AM(UTC)
Rank: Newbie

Joined: 2/6/2012(UTC)
Posts: 0

Hello Zach,


My mistake, i didnt explain why i didnt use the binaryFormatter serializer/deserializer on both side.


Actually, when i reference into the client side project (MF4.1 application) the Microsoft.SPOT.Debugger.dll (from the folder : 'C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Tools\'). I have got the following error code during the compile-time operations : "Erreur 1 0x81010009" 


I have found on internet this is apprently the error the compiler gives when trying to do something the language doesn't support.


It's weird, cause i was able to use the same Microsoft.SPOT.Debugger.dll on a server side project (.net4 application) without any problems


Any ideas on it?


thx a lot for your help,


Best regards,


Cedric

Zach Libby
#8 Posted : Friday, February 10, 2012 1:15:54 PM(UTC)
Zach Libby

Rank: Tinkerer

Joined: 2/5/2010(UTC)
Posts: 243

Was thanked: 8 time(s) in 8 post(s)
Did you make sure you compiled your application with .net4 and choose x86 as the target platform in the project settings? Also, if the reference property "Copy Local" is set to true you will need to also reference the debugger assembly's dependencies (Microsoft.SPOT.Tasks.dll) and you may also need to include Microsoft.Build.Utilities.v4.0.dll (int c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0). I think you can get away with changing "Copy Local" to false in the reference properties, but you may need to manually remove the old debugger assembly from your projects output before compiling.

Zach
alextroto
#9 Posted : Wednesday, July 04, 2012 5:02:56 AM(UTC)
Rank: Newbie

Joined: 7/4/2012(UTC)
Posts: 0

Hi Cedric,
Did you make it ?
I'm also trying to deserialize .a netmf byte array on desktop, but without success.
Desktop project it's compiling, but I'm getting this error :
SerializationException: Cannot find type for hash 5B619C0D
Thanks,
Alex
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.143 seconds.