1

Resolved

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

description

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.

comments

schizoidboy wrote Oct 10, 2007 at 1:24 PM

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

Thanks!
Kevin

schizoidboy wrote Oct 10, 2007 at 3:12 PM

Hi, this has been fixed in release 0.2.27.0:

[url:http://www.codeplex.com/publicdomain/Release/ProjectReleases.aspx?ReleaseId=7632]

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

Thanks!