empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
398 stars 91 forks source link

MemoryStream's internal buffer cannot be accessed. #90

Closed iPazooki closed 4 months ago

iPazooki commented 4 months ago

I'm using .NET 8 and use the latest version of the PDFSharp (6 and 6.1pre) but I'm getting this error "MemoryStream's internal buffer cannot be accessed." when I use this code:

var contentSteam = new MemoryStream(imageForPage);

XImage contentXImage = XImage.FromStream(contentSteam);
ThomasHoevel commented 4 months ago

You are using the wrong c'tor.

Use this c'tor to make the buffer accessible:
new MemoryStream(bytes, 0, bytes.Length, true, true)