Correct deserialization with BinaryFormatter
-
How to check Stream contains valid BinaryHeader to avoid deserialization exceptions such as
Binary stream '0' does not contain a valid BinaryHeader
?Чесноков
-
How to check Stream contains valid BinaryHeader to avoid deserialization exceptions such as
Binary stream '0' does not contain a valid BinaryHeader
?Чесноков
Could you post some code ??? so we can see what your trying to do. ?
With great code, comes great complexity, so keep it simple stupid...:-\ :-\
-
Could you post some code ??? so we can see what your trying to do. ?
With great code, comes great complexity, so keep it simple stupid...:-\ :-\
I do not want that deserialization call
formatter.Deserialize(ms);
will result in Exception. Thus I need to check thatMemoryStream ms;
contains valid header which is used internally inBinaryFormatter.Deserialize()
call.Чесноков
-
I do not want that deserialization call
formatter.Deserialize(ms);
will result in Exception. Thus I need to check thatMemoryStream ms;
contains valid header which is used internally inBinaryFormatter.Deserialize()
call.Чесноков
Its not that simple. please provide an sample code from where you get the error. else im unable to help you.
With great code, comes great complexity, so keep it simple stupid...:-\ :-\
-
Its not that simple. please provide an sample code from where you get the error. else im unable to help you.
With great code, comes great complexity, so keep it simple stupid...:-\ :-\
It is very simple, MemoryStream contains your data for deserialization. With
MemoryStream.GetBuffer();
you may get access to underlyingbyte[]
array. It needs to check that in that array first bytes are validBinaryHeader
structure used inernally byBinaryFormatter
during deserialization call. If there is garbage in theMemoryStream
thenBinaryFormatter
will throw exception. I need to avoid that exception and make sure correct data will be passed for deserialization. Finally I found that link that resolves the issue http://primates.ximian.com/~lluis/dist/binary_serialization_format.htm[^]Чесноков