empira / PDFsharp

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

6.1.0-preview-1 errors when opening file in framework 4.8 #91

Closed zlangner closed 4 months ago

zlangner commented 4 months ago

I'm trying out PDFsharp 6.1.0-preview-1 but I'm finding it cannot open a simple PDF. I'm using .net framework net48

Expected Behavior

That I can open the attached PDF using a filestream like I could in version 1.50.5147 2_page.pdf

Actual Behavior

Exception thrown

System.InvalidOperationException : Collection was modified; enumeration operation may not execute

Stack Trace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
   at PdfSharp.Pdf.IO.PdfReader.FinishChildReferences(PdfDictionary dictionary, PdfDocument document, HashSet`1 finishedObjects)
   at PdfSharp.Pdf.IO.PdfReader.FinishItemReferences(PdfItem pdfItem, PdfDocument document, HashSet`1 finishedObjects)
   at PdfSharp.Pdf.IO.PdfReader.FinishReferences(PdfDocument document)
   at PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openMode, PdfPasswordProvider passwordProvider)
   at PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, PdfDocumentOpenMode openMode)

Steps to Reproduce the Behavior


using (var fs = File.OpenRead(pathToPdfFile))
{
    var valid = PdfReader.TestPdfFile(fs); // works and is valid
    var doc = PdfReader.Open(fs, PdfDocumentOpenMode.Import); // error thrown
}

Additional information

My full use case is very similar to the Combine Documents Variant 2 example from the PDFSharp docs. My actual code is erroring when XPdfForm.FromStream(stream) is called but the above code shows the same error since it's happening while opening the file.

ThomasHoevel commented 4 months ago

Duplicate: https://github.com/empira/PDFsharp/issues/70 Fixed in the meantime, but not yet published.

zlangner commented 3 months ago

I just wanted to follow up on this. Using 6.1.0-preview-2 all of my use cases now work. Thanks for releasing that!