C1PdfViewer crashes when using multiple instances

Posted by: daniel.erdei on 28 January 2022, 12:51 am EST

  • Posted 28 January 2022, 12:51 am EST


    I have a test application that uses C1PdfViewer.

    I have outsourced the C1PdfViewer into a sample user control UserControl1.
    When using only one instance of UserControl1 in my application, everything works as expected (i can scroll, search in pdf ...).

    As soon as I add a second, third, fourth ... instance of UserControl1 in another tab, the first one works as expected, but all the others throw an exception when I scroll down some pages.

    I have included my test PDF in the root folder, next to the solution. To open a pdf in the active tab, you need to enter the path to the test PDF in the textbox labeled "PDF-Pfad" and click on the button "PDF öffnen" afterwards.

    If you load the pdf in Tab 1 and scroll to the bottom, everything works fine. If you do the same in Tab 2 or 3, the following exception gets thrown and my application crashes:

    Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
    at C1.WPF.PdfViewer.C1PdfViewer.RaisePropertyChanged(String propertyName)
    at C1.WPF.PdfViewer.C1PdfViewer.OnVerticalOffsetChanged(Object sender, EventArgs e)
    at C1.WPF.C1ListViewer.RaiseVerticalOffsetChanged()
    at C1.WPF.C1ListViewer.OnVerticalOffsetChanged()
    at C1.WPF.C1ListViewer.<>c.<.cctor>b__18_2(DependencyObject d, DependencyPropertyChangedEventArgs a)
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)

    How can I use multiple instances of C1PdfViewer without getting that exception when scrolling some pages further down?

    Note: I must not use C1FlexViewer, because it lacks of functionality or has some deal-breaker bugs, for example: https://www.grapecity.com/forums/wpf-edition/c1flexviewer---search-with

    I am using the following C1 assemblies:
    • C1.WPF.4.5.2.dll
    • C1.WPF.Document.4.5.2.dll
    • C1.WPF.PdfViewer.4.5.2.dll
    • C1.WPF.Zip.4.5.2.dll
    WPF_Forschung_PDF_ComponentOne - 25.01. TICKET.zip
  • Marked as Answer

    Replied 30 January 2022, 9:29 pm EST

    Hello Daniel,

    Thanks for the sample and StackTrace..

    The Exception is originally throws on RaisePropertyChanged.

    In your provided sample you are updating a textbox's text to notify the user that which PageNumber is currently visible. For that you have set binding on it and you are also updating textbox's text manually through code-behind on PageNumberChanged.

    JFYI, PageNumber property updates on loading, scrolling and navigating pages even it is on the same page. At the time of scrolling, PageNumberChanged event will not fire.

    To prevent this behavior, you need to update textbox's text when PageNumber property is changing, For that you can handle PropertyChanged event of PdfViewer instead PageNumberChanged. (see code snippet)

    private void pdfViewer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    tbPage.Text = pdfViewer.PageNumber.ToString();

    Please refer the modified attached sample for the same :
    WPF_Forschung_PDF_ComponentOne - 25.01. TICKET_Mod.zip

    JFYI, PdfViewer is in maintenance mode(Replaced with FlexViewer) and not under active development. Hence there'll no bug fixes.

    Best Regards,
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels