Custom file DeSerialization

G

Guest

Hi,

Introduction:
****************
I am trying to DeSerialize a file that was created by an unmanaged
application by the binary formatter, to achieve that I am implementing the
following ISerializable methods:
1. GetObjectData(SerializationInfo info, StreamingContext context)
2. constructor(SerializationInfo info, StreamingContext context)

The problem:
****************
Any .NET Object has a unique identifier associated with it ( a GUID ), the
BinaryFormatter uses this GUID to resolve the type of the object being
DeSeriailized, When trying to DeSerialize a file that was created by a non
..NET application this GUID is not available, thuse the BinaryFormatter
doesn't know the serialized type and the DeSerialization fails.

Questions:
****************
1. Is it possible to DeSerialize a propriotary file created by an unmanaged
application ( one that doesn't contain the type GUIDs ).
2. Is it possible to manually specify the type being deserialized.
3. May that be realted to the BinaryFormatter.UnsafeDeserialize API ?
 
G

Guest

Nadav said:
Questions:
****************
1. Is it possible to DeSerialize a propriotary file created by an unmanaged
application ( one that doesn't contain the type GUIDs ).
Yes, you can create a class that implements the ISerializationSurrogate
interface to handle the deserialization for you. If the file has a
different format than the BinaryFormatter or SoapFormatter uses, you'll
also have to create your own Formatter.
2. Is it possible to manually specify the type being deserialized
When you add your ISerializationSurrogate to the SurrogateSelector
associated with your Formatter you specify the type the implementation
is a serialization surrogate for.
3. May that be realted to the BinaryFormatter.UnsafeDeserialize API ?
Related in what way?

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
S

Sahil Malik

I have a slightly different approach to the problem.

The file that you are trying to deserialize was created by a non .NET i.e.
non binaryformatter or even IFormatter kind of situation. Right?

ISerializable or SerializableAttribute will do you no good then.

Why?

Because these are used by the formatter, and formatters do a lot more than
"just deserialize". For example they will verify the versions,
publickeytoken .. etc. etc.

You need to create your own serialization mechanism OR if you absolutely
must insist on using ISerializable you'd have to write your own brand new
formatter.

Regards #2 - The type being deserialized is always object, you'd have to
box/unbox.
Regards #3 - No, and I am glad it isn't there as it makes no sense.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top