NullReferenceException in PdfViewerControl on Escape Key Press

I am encountering a NullReferenceException when pressing escape key when the pdf viewer is focused


The exception message is as follows:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

After the exception, visual Studio automatically decompiled the source code and pointed to the following line where the exception occurs:


// DocumentView.cs

internal void OnEscKeyPressed()
{
if (SelectedBounds.Count > 0 || PolygonPoints.Count > 0 || IsPolylineInProgress || SelectedAnnotation is PdfViewerTextMarkupAnnotation)
{
CloseSelection();
}
else if (FreeTextSelectedBounds.Count > 0)
{
DeselectFreeTextAnnotation();
}
else if (m_parent != null && m_parent.pdfViewerControl != null && m_parent.pdfViewerControl.m_documentToolbar != null && m_parent.pdfViewerControl.m_documentToolbar.m_btnAnnotation != null && m_parent.pdfViewerControl.m_documentToolbar.m_btnAnnotation.IsChecked == true)
{
m_parent.pdfViewerControl.m_documentToolbar.m_btnAnnotation.IsChecked = false;
}
else if (m_parent != null && m_parent.RegionsToBeRedacted != null && m_parent.PageRedactor != null)
{
if (m_parent.RegionsToBeRedacted.Count == 0)
{
m_parent.HideRedactionToolbar();
}
else if (m_parent.RegionsToBeRedacted.Count > 0 && m_parent.PageRedactor.EnableRedactionMode && !m_isPropertieWindowOpened)
{
MouseOveredRegion = null;
m_parent.ClearPreMarkRegions();
m_parent.m_isMarked = false;
}
}
else if (m_parent != null && m_parent.pdfViewerControl != null && m_parent.pdfViewerControl.m_documentToolbar != null && !m_isPropertieWindowOpened && !m_isPopupOpened)
{
m_parent.pdfViewerControl.m_documentToolbar.ResetBackground(null);
}
m_isPopupOpened = false;
Keyboard.Focus(imageProvider._selectionCanvas);// imageProvider is null
}


SyncfusionPdfViewer.WPF version: 27.1.50


6 Replies

KG Krithika Ganesan Syncfusion Team March 12, 2025 10:30 AM UTC

Hi Joseph,

 

We were unable to reproduce the reported issue using the provided information. For your reference, we have attached a sample and a video demonstrating our attempt to reproduce the issue on our end.

 

If the issue persists with the provided sample, please share detailed replication steps. Alternatively, you may modify the sample to reproduce the issue and share it with us.

Additionally, please provide a recorded video demonstrating how to reproduce the issue. This will help us investigate further.

 

Regards,

Krithika



KG Krithika Ganesan Syncfusion Team March 12, 2025 10:37 AM UTC

You can find the attached sample and video below for your reference.


Attachment: EscapeKey_463a107b.zip


JO Joseph March 12, 2025 10:49 AM UTC

after the main window starts up simply click on the pdf viewer control then press escape key

note: use the provided sample project


Attachment: sample_video_e119e275.zip


YM Yathavakrishnan Mohan Syncfusion Team March 13, 2025 06:07 AM UTC

We were able to reproduce the reported issue with the provided details on our end, and currently we are analyzing it. We will provide further details on March 17th, 2025.



YM Yathavakrishnan Mohan Syncfusion Team March 17, 2025 02:06 PM UTC

We have confirmed the issue “Null Reference Exception Occurred in WPF PDFViewer when pressing the Escape key” as a defect in our product and we will include the fix for this issue in our Weekly NuGet Release after our 2025 Volume 1 main release which is expected to be available on April 1, 2025.

 

Please use the below feedback link to track the status of the reported bug.

Null Reference Exception occurred in WPF PDFViewer when pressing the Escape key in WPF | Feedback Portal

 

Note: If you require a patch for the reported issue in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy.

 

Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”



YM Yathavakrishnan Mohan Syncfusion Team April 1, 2025 02:10 PM UTC

We have included the fix for this “Null Reference Exception Occurred in WPF PDFViewer when pressing the Escape key” in our latest weekly release (29.1.35). Upgrade to the latest version, to get the issue resolved.

 

Root Cause:

Since no PDF was loaded in the PdfViewer, the canvas was null, which caused the error.

 

Please use the below link to download our latest NuGet,

Nuget Link:

NuGet Gallery | Syncfusion.PdfViewer.WPF 29.1.35

 

Feedback link

Null Reference Exception occurred in WPF PDFViewer when pressing the Escape key in WPF | Feedback Portal


Loader.
Up arrow icon