[Mono-list] BinaryFormatter, Deserialize(), casting throws exception.
Robert Jordan
robertj at gmx.net
Tue Aug 29 03:46:53 EDT 2006
Wiktor Grębla wrote:
> Hi.
>
> Why is this code:
>
> Stream fs = File.OpenRead("./test.obj");
> BinaryFormatter bf = new BinaryFormatter();
>
> Mydata d = (Mydata)bf.Deserialize(fs);
>
> throwing: Unhandled Exception: System.InvalidCastException: Cannot cast
> from source type to destination type.
Because the deserialized data is not of type "Mydata".
What's the output of
Console.WriteLine (bf.Deserialize(fs).GetType ().FullName)
?
Robert
More information about the Mono-list
mailing list