This message was discovered on microsoft.public.dotnet.framework.remoting.
| piyush |
Hello, I am trying to use shared memory mapped files for IPC between two applications, one of which may be in C++ (non .NET envi)
As a first step I am trying to get serialization / deserializtion working within a single application and getting exceptions and errors.
"Binary stream does not contain a valid Binary header, 0 possible causes, invalid stream or object version change between serialization and deserialization"
The code is (CURRENTLY ITS IN A SINGLE APPLICATION ) :
[StructLayout (LayoutKind.Sequential)] [Serializable] public struct MYREC { public string blah; public string foo; }
MYREC myRecord = new MYREC(); myRecord.blah = "blah"; myRecord.foo = "foo";
MemoryStream ms = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter();
bf.Serailize(ms, myRecord); byte[] buffer = ms.GetBuffer(); int size = Marshal.Sizeof(myRecord); for(int i=0;i < size; ++i) { Marshal.WriteByte( (IntPtr) (mp.ToInt64() + i), buffer[i]); }
//WHAT EXACTLY SHOULD BE IN SECOND APPLICATION, BUT IS IN SAME APP NOW
MYREC display = new MYREC(); MessageBox.Show ("Trying ot get the structure back here:"); byte[] rec = new byte[size]; for(int j=0 ; j < size ; j++) { rec[j] = Marshal.ReadByte ( (IntPtr) (mp.ToInt64() + j)); }
BinaryFormatter newbf = new BinaryFormatter(); MemoryStream newms = new MemoryStream (rec); newms.Position = 0; //dont know if this should be there display = (MYREC) newbf.Deserialization(newms);
Any clues are greatly appreciated .. and its urgent please !
Thanks ! Piyush
|
|
| |
| | |
|
|
|
|