473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Serialize Deserialize troubles please help !

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
Nov 16 '05 #1
0 876

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
3
by: Amsteel | last post by:
I got something like this in VB.Net <Serializable()> Public Class YQProfileC Inherits CollectionBase Public Sub Save2File(ByVal FileName As String) Dim IFormatter As New BinaryFormatter() Dim...
1
by: Bsiang Tan | last post by:
I try to serialize my object into xml it work, but I can't deserialize it back. I get an exception.. :- An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred...
0
by: Fred Heida | last post by:
Hi Al, i have a funny problem.. i you can call it funny.. what i have is 2 assemblies, the first one does nothing other then Application.Run(new MyForm())
2
by: alexandre martins | last post by:
Every time i try to make Deserialize the computer gives me the folowing error: "End of Stream encountered before parsing was complete" the code that i'm running is simple and is based on an...
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
4
by: Hone | last post by:
I'm trying to serialize/deserialize the XML for an RSS 1.0 Feed (i.e. RDF) and the root element, as required by the standard, looks like this: <rdf:RDF ...> </rdf:RDF> However, I've tried...
4
by: djidan | last post by:
hi, i am a newbe to c#, i'm trying to send en custom object from a client to a server, after reading a lot on the web ifound that i need to use: BinaryFormatter, MemoryStream, and Serialize...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.