PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PDFsharp: assertion failure: "Should not come here"
https://forum.pdfsharp.net/viewtopic.php?f=3&t=4305
Page 1 of 1

Author:  equinox [ Sun Dec 05, 2021 8:59 pm ]
Post subject:  PDFsharp: assertion failure: "Should not come here"

I am using PDFsharp version 1.50.4740.0 (copyrighted 2005-2017 in the DLL file).

The simple C# code below is supposed to load a PDF, copy it (one page at a time), and save the result. It has worked well in the past; I use a more complex version to shorten PDFs by removing some pages.

However, with one particular PDF file (attached), it fails with an assertion failure, saying "Should not come here". You can see the error text screenshotted here (it's very long and I don't know how to copy text from that message box):
https://github.com/empira/PDFsharp/issues/152

Does this assertion failure indicate a bug in PDFsharp?
What is the real problem and how can I resolve it? Thanks.

Code:
using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace PdfTest
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            string inFile = @"C:\Users\home\Desktop\2304.pdf";
            string outFile = @"C:\Users\home\Desktop\output.pdf";

            int start = 1, end = 2; // we know it has exactly 2 pages

            using (PdfDocument src = PdfReader.Open(inFile, PdfDocumentOpenMode.Import))
            {
                using (PdfDocument dst = new PdfDocument())
                {
                    for (int i = start; i <= end; i++)
                    {
                        dst.Pages.Add(src.Pages[i - 1]);
                    }

                    dst.Save(outFile);
                }
            }
        }
    }
}

Author:  argee [ Tue Dec 21, 2021 1:09 am ]
Post subject:  Re: PDFsharp: assertion failure: "Should not come here"

I just started seeing this same message recently when I run my application that performs a similar type of function.
It seems like the PDF is still being compiled properly even with the error messages (I just kept clicking "Ignore").

I updated my PDFSharp library to 1.51.5185 (3/4/2019) and now it runs without errors.

Hope that helps.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/