ObjectUtilities.SerializeObjectToBinary(object o) is returning wrong buffer.


The ObjectUtilities.SerializeObjectToBinary(object o) function is returning the buffer obtained via MemoryStream.GetBuffer() which is an internal buffer maintained by MemoryStream and is not supported to hold the exact serialized bytes (will contain extra bytes at the end). The fix would be to use MemoryStream.ToArray() function.
The issue can be confirmed by comparing the return byte[] of GetBuffer() and ToArray() functions. The former would be bigger than the latter as it would contain unused space at the end.
The current implementation might still work in most of the cases, but it is not the right thing by principle.


schizoidboy wrote Oct 10, 2007 at 12:24 PM

Hi, thank you very much for this fix, I will put it in the next release.


schizoidboy wrote Oct 10, 2007 at 2:12 PM

Hi, this has been fixed in release


I notice that this change causes the byte array to be copied, but that is better than non-deterministic behavior.