moonpdf icon indicating copy to clipboard operation
moonpdf copied to clipboard

NullReferenceException when i call OpenFile method

Open jlpuma24 opened this issue 6 years ago • 13 comments

Hi, a have a couples of issues regarding the OpenFile method calls, i create my component like this:

image

After that i call this method:

image

When the route of PDF on my computer and gives me NullReferenceException

Can you help me with this? Thanks!

jlpuma24 avatar May 07 '18 04:05 jlpuma24

@reliak can you help me please? Thanks a lot

jlpuma24 avatar May 08 '18 00:05 jlpuma24

I guess you have opened your pdf file in Loaded event. Maybe you should use this.UpdateLayout() to force UI to update, so visualtree can find the scrollview which is the templatechild of inner panel

Minimum006 avatar Jan 14 '19 10:01 Minimum006

@jlpuma24 Hi, how did you solve this problem?

seahandsome avatar Nov 07 '19 06:11 seahandsome

Hi, I have the same issue overhere, it already took me hours.

My application consists of tabPages, let's say a Base tab and a Manual tab for displaying PDF manual files. The first time I switch from BaseTab to ManualTab I get the exception, but when I switch back to BastTab and to ManualTab a second time, it displays the PDF beautifully!

Visual Studio 2015, .NET 4.5.2, WPF application.

Any idea what I am doing wrong?

focussing avatar Feb 14 '20 08:02 focussing

@reliak did you encounter this also?

focussing avatar Feb 14 '20 08:02 focussing

@Minimum006 adding this.UpdateLayout() just before calling the OpenFile method does not help...

focussing avatar Feb 14 '20 09:02 focussing

For the record; this is the error message. System.NullReferenceException: Object reference not set to an instance of an object. at MoonPdfLib.ContinuousMoonPdfPanel.Load(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\ContinuousMoonPdfPanel.xaml.cs:line 65 at MoonPdfLib.MoonPdfPanel.LoadPdf(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 232 at MoonPdfLib.MoonPdfPanel.Open(IPdfSource source, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 207 at MoonPdfLib.MoonPdfPanel.OpenFile(String pdfFilename, String password) in C:\develop\moonpdf-master\src\MoonPdfLib\MoonPdfPanel.xaml.cs:line 189

focussing avatar Feb 14 '20 12:02 focussing

@Minimum006 I see in the debugger that the following code is causing the exception; this.virtualPanel and this.scrollViewer are null the first time this is called.

        {
            this.virtualPanel = VisualTreeHelperEx.FindChild<CustomVirtualizingPanel>(this);
            this.scrollViewer = VisualTreeHelperEx.FindChild<ScrollViewer>(this);
            this.virtualPanel.PageRowBounds = this.parent.PageRowBounds.Select(f => f.SizeIncludingOffset).ToArray();
            this.imageProvider = new PdfImageProvider(source, this.parent.TotalPages,
                                        new PageDisplaySettings(this.parent.GetPagesPerRow(), this.parent.ViewType, this.parent.HorizontalMargin, this.parent.Rotation),
                                        password: password);

            if (this.parent.ZoomType == ZoomType.Fixed)
                this.CreateNewItemsSource();
            else if (this.parent.ZoomType == ZoomType.FitToHeight)
                this.ZoomToHeight();
            else if (this.parent.ZoomType == ZoomType.FitToWidth)
                this.ZoomToWidth();

            if (this.scrollViewer != null)
            {
                this.scrollViewer.Visibility = System.Windows.Visibility.Visible;
                this.scrollViewer.ScrollToTop();
            }
        }

focussing avatar Feb 14 '20 14:02 focussing

The author has not been active on github for several years, modify it yourself.

netcore-jroger avatar Feb 15 '20 01:02 netcore-jroger

@netcore-jroger thank you for your message; I am already digging into it; not a clue yet where to fix it

focussing avatar Feb 15 '20 05:02 focussing

@focussing You can look at the example. I used this component many years ago but did not encounter your problem.But I have no environment now

netcore-jroger avatar Feb 18 '20 03:02 netcore-jroger

Hi,

I got this error message when I called the TogglePageDisplay function. The value of the PageRowDisplay attrib in the xaml was SinglePageRow. I changed the PageRowDisplay to ContinuousPageRows and removed the TogglePageDisplay call. It's just a workaround, of course, but it's working for me.

salzschneider avatar Oct 05 '20 13:10 salzschneider

Hi, May help someone :) ran into the same problem, if you want to use PageRowDisplay="ContinuiusPageRows" and you get an error when opening the file, check that you don't use Visible="Collapsed" on the MoonPdfPanel element, use Hidden

PineappleUFO avatar Dec 19 '22 07:12 PineappleUFO