[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

BinaryFormatter Serializing/Deserializing from different apps

Bob Krauth

1/6/2003 10:05:00 AM

I use the BinaryFormatter, serializing to a file from one
app (App1), and trying to deserialize from another (App2).

App2 gives error msg of:

---------
An unhandled exception of
type 'System.IO.FileNotFoundException' occurred in
mscorlib.dll

Additional information: File or assembly name App1, or
one of its dependencies, was not found.
---------

The written file contains:
App1, Version=1.0.1101.83, Culture=neutral,
PublicKeyToken=null

I implemented ISerializable interface - no help.

How can I get App2 to deserialize this file instead of
complaining that it isn't App1?

Thanks,
Bob Krauth



1 Answer

Dave

1/6/2003 12:57:00 PM

0

A type is considered to be part of the assembly it is defined in. One
solution is to add a reference to App1 to the project that created App2 and
deploy App1 along with App2. Another solution is to redefine the object
definition in App2, and then implement a serialization binder to map the
type as defined in App1 to a type defined in App2.

To do this implement a serialization binder. During deserialization this
gives you a chance to
tell the binary formatter which System.Type to use for a given typename. You
need to define a class that derives from SeriazationBinder and in that class
override the BindToType method. When you create the BinaryFormatter object
set its Binder property to an instance of your SerializationBinder class. As
the binary formatter deserializes if it hits a typename for which it does
not already have a System.Type defined for it, it asks the binder for that
System.Type. This gives you a chance to treat a type as defined in one
assembly to
a type as defined in some other assembly. It is up to you to make sure the
types really
are compatible and convertible.



"Bob Krauth" <bob@krauth.com> wrote in message
news:49b001c2b562$c7798e90$8bf82ecf@TK2MSFTNGXA05...
> I use the BinaryFormatter, serializing to a file from one
> app (App1), and trying to deserialize from another (App2).
>
> App2 gives error msg of:
>
> ---------
> An unhandled exception of
> type 'System.IO.FileNotFoundException' occurred in
> mscorlib.dll
>
> Additional information: File or assembly name App1, or
> one of its dependencies, was not found.
> ---------
>
> The written file contains:
> App1, Version=1.0.1101.83, Culture=neutral,
> PublicKeyToken=null
>
> I implemented ISerializable interface - no help.
>
> How can I get App2 to deserialize this file instead of
> complaining that it isn't App1?
>
> Thanks,
> Bob Krauth
>
>
>