Deserialize from MemoryStream throws OutOfMemory exception in C #

This is a Winform C # 3.0 issue.

I want to clone a large (not really large) complex object. To do this lazily, I serialized it to a MemoryStream and used the BinaryFormatter.UnsafeDeserialize (MemoryStream, null) method to get the cloned object. Inside the UnsafeDeserialize () method, an OutOfMemory exception always occurs. The memory should be sufficient.

I read a little about this as a .net error, but am not sure if it is here.

Does anyone know why this is happening? Any desktop? Thank.

+2
source share
4 answers

Perhaps a stupid question, but do you remember to rewind the MemoryStream to the beginning of the stream before deserializing?

.

+2

UnsafeDeserialize Deserialize?

+1

?

, . , , ; - a tree graph? (.. - ? ).

+1

FileStream , .

0

All Articles