We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

NullReferenceException when loading PDF

Hi there

I am getting a NullReferenceException when I try to load a PDF in the viewer:

  at Syncfusion.SfPdfViewer.XForms.MobileToolbar.Reset () [0x00000] in <5cdd8e7e5b5c498dbc7f5128ce6c9021>:0 
  at Syncfusion.SfPdfViewer.XForms.Toolbar.Reset () [0x00010] in <5cdd8e7e5b5c498dbc7f5128ce6c9021>:0 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.OnInputFileStreamChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x0036c] in <5cdd8e7e5b5c498dbc7f5128ce6c9021>:0 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:445 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:379 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:316 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:293 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.set_InputFileStream (System.IO.Stream value) [0x00000] in <5cdd8e7e5b5c498dbc7f5128ce6c9021>:0 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.LoadDocument (System.IO.Stream stream) [0x0002e] in <5cdd8e7e5b5c498dbc7f5128ce6c9021>:0 
  at Locate.GUI.PDFViewer+<>c__DisplayClass3_0.<LoadPDFFile>b__0 () [0x00012] in /Users/SPE/Dev/optimise/LocateMobileApp/Locate/Locate/Locate/GUI/PDFViewer.xaml.cs:41 
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSAction.cs:152 
--- End of stack trace from previous location where exception was thrown ---

  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at Locate.iOS.Application.Main (System.String[] args) [0x00001] in /Users/SPE/Dev/optimise/LocateMobileApp/Locate/Locate/Locate.iOS/Main.cs:17 

8 Replies

SS Sathish Sivakumar Syncfusion Team June 17, 2019 01:52 PM UTC

Hi Michael, 
 
Greetings from Syncfusion. 
  
We tried to reproduce the issue “Null reference exception thrown while loading the PDF document in SfPdfViewer in Xamarin.Forms.iOS”, but it is working fine as expected. Kindly refer the sample in the below link which we created to reproduce the reported issue. 
  
  
Kindly share the following details to analyze more on this issue and it will be helpful for us to analyze more on this issue. 
1.       Modify / Simple sample with which the issue could be reproduced. 
2.       Replication procedure to reproduce the issue or screen shot illustrating the issue. 
3.       iOS device details and SDK version. 
4.       Xamarin.Forms version. 
5.       SfPdfViewer version 
6.       PDF document with which the issue could be reproduced 
  
Regards, 
Sathish 



MH Michael Hoffmann June 20, 2019 09:23 AM UTC

Thanks a lot for your answer. Do you have an example where you can pick a PDF file from a list? - or somehow show how to parameterise the viewer?


CP Chris Parker June 21, 2019 01:34 AM UTC

This is happening to me also. The control shows find on the Modal content page but when I call the .LoadDocument method with a stream of pdf data I get the error. The calling page is a Tabbed Page. Nothing code wise changed with the model content page in months and recently started giving me the error. No PDF will display, regardless of size.

A workaround I got working is to not use a Model content page, just place the control on the calling content page and turn visibility on and off.

Not sure if this helps but I was calling the LoadDocument in the "OnAppearing()" event.


CP Chris Parker June 21, 2019 01:52 AM UTC

My stack trace.

  at Syncfusion.SfPdfViewer.XForms.Droid.LinearLayoutEx.RenderPages () [0x000af] in <d4fd4ee3ae5144b993eabb178a053aa3>:0 
  at Syncfusion.SfPdfViewer.XForms.Droid.HorizontalScrollViewEx.RenderPages () [0x00000] in <d4fd4ee3ae5144b993eabb178a053aa3>:0 
  at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.RenderPages () [0x0000b] in <d4fd4ee3ae5144b993eabb178a053aa3>:0 
  at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.LoadDocument (System.IO.Stream inputStream) [0x005ea] in <d4fd4ee3ae5144b993eabb178a053aa3>:0 
  at Syncfusion.SfPdfViewer.XForms.Droid.SfPdfDocumentViewRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x0007d] in <d4fd4ee3ae5144b993eabb178a053aa3>:0 
  at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:173 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:339 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:622 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00179] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:422 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:572 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:122 
  at Syncfusion.SfPdfViewer.XForms.DocumentViewHelper.set_InputFileStream (System.IO.Stream value) [0x00000] in <14304b87cc434146bafc6aa6f1fdb31b>:0 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.OnPdfViewerPropertyChanged (System.String propertyName) [0x00019] in <14304b87cc434146bafc6aa6f1fdb31b>:0 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.OnInputFileStreamChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00348] in <14304b87cc434146bafc6aa6f1fdb31b>:0 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:624 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00179] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:422 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:572 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:122 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.set_InputFileStream (System.IO.Stream value) [0x00000] in <14304b87cc434146bafc6aa6f1fdb31b>:0 
  at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.LoadDocument (System.IO.Stream stream) [0x0002e] in <14304b87cc434146bafc6aa6f1fdb31b>:0 
  at StoryData.Mobile.Views.Screenplay.ScreenplayOverview.Read_OnTapped (System.Object sender, System.EventArgs e) [0x00105] in E:\VSTS\Story Data Platform\StoryData Mobile2\StoryData.Mobile\StoryData.Mobile\Views\Screenplay\ScreenplayOverview.xaml.cs:201 


JP Jhansi Priya Ramesh Syncfusion Team June 21, 2019 05:29 PM UTC

Hi Chris,  
  
Greetings from Syncfusion.  
  
We have created a simple sample to reproduce the reported issue “NullReferenceException while loading the PDF document in SfPdfViewer” in our side, but the behavior is working as expected. Please find the sample in the below link for your reference.  
  
  
  
Kindly share the following details to analyze more on this issue and assist you with the better solution   
1.       Simple sample/ modify the above sample to reproduce the issue.  
2.       SfPdfViewer version  
3.       Xamarin.Forms version  
4.       Replication procedure to reproduce the issue.  
5.        PDF document with which the issue could be reproduced 
  
 
  
Regards,  
Jhansi 



JP Jhansi Priya Ramesh Syncfusion Team June 21, 2019 05:43 PM UTC

Hi Michael,  
  
Greetings from Syncfusion.  
  
We have created a sample to “Pick PDF file from a list”. Kindly refer the sample in the below link and please let us know if it matches your requirement. 
 
 
If your requirement is different from our observation, kindly share the brief details on your  requirement so that we will assist you with better solution.  
 
  
Regards,  
Jhansi 



CP Chris Parker June 21, 2019 08:11 PM UTC

Thank you for the samples. Here is some info.

Your Sample Code.
  • You are using an older version of Xamarin.Forms (3.2.0.871581)
  • You are not calling the LoadDocument method because you are doing binding. You are a viewing a pdf document that is stored on the phone within the apps space.
My Code
  • I only have access to the latest version on nuget.org which is 17.1.0.52.
  • I am using Xamarin.Forms 3.6.0.344457 which is the last version before they released 4.0.
  • I am calling the LoadDocument and passing in the stream. I got the stream from a document that is located on a server, not the phone.
  • I am displaying the pdfviewer on a content page that is opened in a modal state.
Additional Information
1. Simple sample/ modify the above sample to reproduce the issue.
Upgrading your sample to use the same version of Xamarin.Forms that I'm using, crashes your sample on InitializeComponent() method within the PDFViewerCustomToolbar content page constructor.

2. SfPdfViewer version  
17.1.0.52

3. Xamarin.Forms version  
3.6.0.344457

4. Replication procedure to reproduce the issue.  
From main form display a form in modal mode and use the LoadDocument() method. Pass in a stream of a PDF document that is retrieved from a URI not one that is on the device.

5. PDF document with which the issue could be reproduced 
I have attached a document that generates the error to this post.

Attachment: 2cbbd1a001644392b2bd99453f59fe37_9eb715b9.zip


SS Sathish Sivakumar Syncfusion Team June 24, 2019 09:51 AM UTC

  
Hi Chris, 
 
Thank you for your update. 
 
It seems you have checked the sample which we delivered to another customer. We have shared the sample for your requirement already in our previous updates. However based on the information provided in your update, we have updated the Xamarin.Forms v3.6.0.344457 and SfPdfViewer v17.1.0.52 and loaded the Pdf document from URL link. We could see the document is loaded properly in SfPdfViewer in Xamarin.Forms (iOS). Please find the modified sample in the below link. 
 
 
Kindly share the following details to analyze more on this issue and assist you with the better solution   
  
·        Simple sample/ modify the above sample to reproduce the issue.   
·        Replication procedure to reproduce the issue.   
·        iOS SDK version 
·        iOS physical device or simulator details with version 
·        XCode version 
·        Mac machine details 
 
Regards,
Sathish
 
 


Loader.
Live Chat Icon For mobile
Up arrow icon