all groups > c# > january 2005 >
You're in the

c#

group:

Custom file DeSerialization



Custom file DeSerialization Nadav
1/5/2005 10:53:01 PM
c#: 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 ?
--
Nadav
Re: Custom file DeSerialization Sahil Malik
1/6/2005 10:43:59 AM
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


[quoted text, click to view]

Re: Custom file DeSerialization Anders Norås [MCAD]
1/6/2005 11:13:33 AM
[quoted text, click to view]
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.
[quoted text, click to view]
When you add your ISerializationSurrogate to the SurrogateSelector
associated with your Formatter you specify the type the implementation
is a serialization surrogate for.
[quoted text, click to view]
Related in what way?

Anders Norås
AddThis Social Bookmark Button