When is it safe to use GetBuffer() of Remobjects.SDK.Binary buffer - Avoiding error "MemoryStream's internal buffer cannot be accessed"

I have a RemObjects.SDK.Type.Binary object of size 31MB and when I call the GetBuffer() function it throws exception “MemoryStream’s internal buffer cannot be accessed”.

The Binary object was created using a byte[] array so I assumed the stream consisted of one single byte array.

However, calling GetBuffer() returns “MemoryStream’s internal buffer cannot be accessed”

I assume if change my code so it uses the stream functions that the code will work however I am curious when is it safe to call GetBuffer()?

image

Hi,

from MemoryStream.GetBuffer Method (System.IO) | Microsoft Learn :

To create a MemoryStream instance with a publicly visible buffer, use MemoryStream, MemoryStream(Byte[], Int32, Int32, Boolean, Boolean), or MemoryStream(Int32).