Your memory is overloaded. You allocate a large size memory to heap. Try next type for this case:
ReadOnlySpan<T>
If you want to read memorySpan<T>
If you want modify valuesThat readonly ref struct
type provide safe memory usage and it allocated in stack. The alternative of that it's Memory
. It's readonly struct
In your code i have seen a mistake. Fix it if you copied exact code. The type initialized in using
construction would be disposed after it
using MemoryStream memoryStream = new MemoryStream();
{
currentDocument.Save(memoryStream);
currentDocument.Close(true);
memoryStream.Position = 0;
logger.LogDebug("Position {Position} and Length {Length} CanRead {CanRead}",
memoryStream.Position, memoryStream.Length, memoryStream.CanRead);
byte[] fileData = memoryStream.ToArray();
}
I hope that will help you. Can you give more information and code about it? Remind me if i say wrong