- Home
- Forum
- Xamarin.Forms
- Exception loading PDF File on Android Side
Exception loading PDF File on Android Side
System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.LoadDocument (System.IO.Stream inputStream) [0x001ab] in <3a7a067f010a46fb9644922c745ce452>:0 at Syncfusion.SfPdfViewer.XForms.Droid.SfPdfDocumentViewRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00083] in <3a7a067f010a46fb9644922c745ce452>: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:229 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:358 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:461 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:397 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:334 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:311 at Syncfusion.SfPdfViewer.XForms.DocumentViewHelper.set_InputFileStream (System.IO.Stream value) [0x00000] in <58958fe884e342ac898d77120a7e28c8>:0 at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.OnPdfViewerPropertyChanged (System.String propertyName) [0x00019] in <58958fe884e342ac898d77120a7e28c8>:0 at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.OnInputFileStreamChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x0048c] in <58958fe884e342ac898d77120a7e28c8>: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:463 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:397 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:334 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:311 ewer.set_InputFileStream (System.IO.Stream value) [0x00000] in <58958fe884e342ac898d77120a7e28c8>:0 at Syncfusion.SfPdfViewer.XForms.SfPdfViewer.LoadDocument (System.IO.Stream stream) [0x0005a] in <58958fe884e342ac898d77120a7e28c8>:0 at Avantxa.Vistas.PDFViewer.OnAppearing () [0x00299] in /Users/maxal2/Desktop/APP/Avantxa/Avantxa/Vistas/PDFViewer.xaml.cs:63 |
It only happens when runs on Android (but not on all phones) and since I updated SfPdfViewer to the last version.
- SfPdfViewer 18.3.0.44
- Xamarin.Forms 4.8.0.1560
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:syncfusion="clr-namespace:Syncfusion.SfPdfViewer.XForms;assembly=Syncfusion.SfPdfViewer.XForms" mc:Ignorable="d" x:Class="ProductName.PdfViewerPage"> <ContentPage.Resources> <ResourceDictionary> <syncfusion:Toolbar x:Key="ToolbarSettings"> <syncfusion:Toolbar.Enabled>false syncfusion:Toolbar.Enabled> syncfusion:Toolbar> ResourceDictionary> ContentPage.Resources> <ContentPage.Content> <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> Grid.RowDefinitions> <syncfusion:SfPdfViewer Grid.Row="0" x:Name="PdfControl" InputFileStream="{Binding DocumentSource}" Toolbar="{StaticResource ToolbarSettings}" BookmarkNavigationEnabled="False"/> <Button Grid.Row="1" Text="Close" Command="{Binding Close}" VerticalOptions="End" HorizontalOptions="CenterAndExpand" /> Grid> ContentPage.Content> ContentPage>
public class PdfViewModel : ViewModel { private Stream documentStream; public PdfViewModel() { Close = new Command(CloseHandler); } async void CloseHandler(object obj) { await App.Current.MainPage.Navigation.PopModalAsync(); } public Stream DocumentStream { get => documentStream; set { if (value != documentStream) { documentStream = value; OnPropertyChanged(); } } } public ICommand Close { get; } }
public abstract class ViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }
var viewModel = new PdfViewModel { DocumentStream = stream // stream is valid, has data and has seeked position 0 from the start of the stream. }; var page = new PdfViewerPage { BindingContext = viewModel, }; try { await App.Current.MainPage.Navigation.PushModalAsync(page); } catch (Exception ex) { log.Error(TAG, ex.Message); // this is just a simple log provider and you don't need this to get the example working log.Error(TAG, ex.StackTrace); }So, the code is in a Command attached to a Button on a ContentPage that was shown with PushModalAsync() (we do not use a NavigationPage as we do not show pages in a navigation stuck - all sub forms are modal.)
Any ideas?
I have to reinstall the old version of SfPdfViewer (18.3.038)
Does that version work with the latest Xamarin Forms?
We have faced the issue in the weekly NuGet version of 18.3.0.44 while loading the document in the Xarmarin Forms Android and the fix for the issue is available on the custom NuGet in the link below.
Note: Kindly follow the steps to clear the NuGet cache and then install patched NuGet to get the issue resolved.
Regards,
Satheesh Palanisamy.
YesI'm working with Xamarin.Forms 4.8.0.1560 and SfPdfViewer 18.3.038, all runs perfectly
Reverte back Xamarin.Forms 4.8.0.1560 and SfPdfViewer 18.3.038 Not working with Release.
|
@ Satheesh when can we expect a fix on nuget?
I was expecting a weekly nuget update on the 3rd, but it seems nothing has been released yet?
|
The fix for the issue, “Application crashes with null reference exception while loading in Xamarin Forms Android Platform” is resolved in 2020 Volume 3 service pack release v(18.3.0.47). Kindly update the mentioned version to resolve the issue. |
Hi we are having this issue in 19.2.0.44 again. I noticed this issue seem to be recurring (I see articles in 2018, 2019 and 2020 having the same crash stack trace). Can we please have a fix? At least we want a way so it wouldn't crash the whole app (which is currently impossible).
On our emulator, we have the problem randomly as well though we cannot know exactly what causes it. The same file that crashed would work well next time. I do not know what causes it but here is from user report from Firebase Crashlytics:
```
Fatal Exception: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
at Syncfusion.SfPdfViewer.XForms.Droid.ScrollViewEx.<LoadDocumentWorker_RunWorkerCompleted>b__1152_0 (System.Object _) [0x00017] in <d093d8495fd04c46ab2b856f568b0d43>:0
at Android.App.SyncContext+<>c__DisplayClass3_0.<Send>b__0 () [0x00000] in <5178e605439148a0b87853e9db2bfd5f>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <5178e605439148a0b87853e9db2bfd5f>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <5178e605439148a0b87853e9db2bfd5f>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.62(intptr,intptr)
at mono.java.lang.RunnableImplementor.n_run(RunnableImplementor.java)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6819)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:497)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:912)
```
It's a NullReferenceException, wouldn't it be easy to find the problem if you have the source code?
We were unable to reproduce the issue, “Application crashes with null reference exception while loading ” and it is working as expected., Could you please try the below-provided sample and let us know whether we have missed out anything while replicating the issue.
Kindly share the following details to analyze more on this issue and assist you with the better solution
4. Replication video/procedure to reproduce the issue.
Regards,
Vikram
- 13 Replies
- 8 Participants
- Marked answer
-
FR Francisco
- Oct 29, 2020 06:35 PM UTC
- Sep 28, 2021 08:46 AM UTC