SfPdfViewer LoadDocumentAsync cause crash on android releasebuild

SfPdfViewer LoadDocumentAsync cause crash on android release build 

public PagePDF(Stream stream, bool xml = true, bool isPrintPos = false, bool isSignature = false) : base(false,
false)
{
link = null;
isXml = xml;
PrintPos = isPrintPos;
pdfStream = stream;
Sign = isSignature;
SetPDFView();
InitToolbar();
}


when tried to load the stream it crash

await pdfView.LoadDocumentAsync(pdfStream, null, FlattenOptions.None, new CancellationTokenSource());

i had've tried many configuration but none of them work

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0-android|AnyCPU'">
<!-- <RuntimeIdentifiers>android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>-->
<AndroidUseAapt2>True</AndroidUseAapt2>
<AndroidPackageFormat>aab</AndroidPackageFormat>
<!-- <AndroidLinkMode>SdkOnly</AndroidLinkMode>-->
<!-- <AndroidAotAdditionalArguments>no-write-symbols,nodebug</AndroidAotAdditionalArguments>-->
<!-- <DebugSymbols>False</DebugSymbols>-->
<!-- <RunAOTCompilation>false</RunAOTCompilation>-->
<!-- <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>-->
<!-- <AotAssemblies>true</AotAssemblies>-->
<!-- <EnableLLVM>false</EnableLLVM>-->
<!-- <OptimizationPreference>Speed</OptimizationPreference>-->
<AndroidLinkTool>r8</AndroidLinkTool>

<!-- Debug config-->
<!-- <DebugType>full</DebugType>-->
<!-- <DebugSymbols>true</DebugSymbols>-->
<!-- <AndroidDebuggable>true</AndroidDebuggable> &lt;!&ndash; For Android &ndash;&gt;-->
<!-- <UseInterpreter>all</UseInterpreter> &lt;!&ndash; For iOS, if reflection issues occur &ndash;&gt;-->
<Optimize>false</Optimize> <!-- Optional, reduces optimization for easier debugging -->
<!-- <AndroidLinkMode>None</AndroidLinkMode>-->
<!-- Debug config-->
</PropertyGroup>

 


7 Replies

BS Bharathi Selvam Syncfusion Team July 31, 2025 03:09 PM UTC

Hi Nguyen Thinh,

Thank you for contacting Syncfusion support.


We have created a sample project to load a PDF stream using the LoadDocumentAsync method in the PDF Viewer. We tested this on an Android emulator using latest version 30.1.42 in Release mode, and the PDF loaded successfully without any crashes.


However, we were unable to reproduce the issue, “PDF Viewer crashes when loading the PDF using LoadDocumentAsync method on Android platform in Release mode.” Please find the attached video and sample project we used for testing.


Could you kindly review them and let us know if we missed any steps while attempting to replicate the issue?


Could you please review them and let us know whether we have missed while replicating the issue?

Please provide the following details to help us analyze the issue further:

  • PDF in which issue occurs as it may be specific to the document.
  • Confirm whether this issue occurs only in the release mode and not in debug mode
  • Exact steps to reproduce the issue if we miss anything
  • Device model and OS version, as the issue might be device-specific
  • A modified sample, if available
  • Confirm whether it occurs consistently.
  • .NET MAUI package versions (Microsoft.Maui.Compatibility and Microsoft.Maui.Controls)
  • Any other relevant information that might help us reproduce the issue

Regards,

Bharathi S


Attachment: SampleAndVideo_980b9a02.zip


NT Nguyen Thinh replied to Bharathi Selvam August 1, 2025 03:09 AM UTC

  1. I've tried many pdf file, every time it crash
  2. Yes, it works normal in debug mode only crash in release 
  3. I've attached the sample project below
  4. Tried many device
  5. Already
  6. Yes, it occurs consistently.

Attachment: sampletest_d0b7dc1a.zip


BS Bharathi Selvam Syncfusion Team August 1, 2025 04:06 PM UTC

Hi Nguyen Thinh,


Thank you for sharing the details.

We were able to reproduce the issue where the PDF Viewer crashes when loading a PDF using the LoadDocumentAsync method on the Android platform. We are currently in the process of validating the issue and will update you with further details by August 5, 2025.


Regards,

Bharathi S



NT Nguyen Thinh replied to Bharathi Selvam August 5, 2025 08:44 AM UTC

Hey! Any update yet?



BS Bharathi Selvam Syncfusion Team August 5, 2025 02:33 PM UTC

Hi Nguyen Thinh,


After further analysis, we have identified that the crash occurring when loading a PDF using the LoadDocumentAsync method on Android on the release mode is related to one of our dependent libraries. Our team is currently validating and prioritizing the fix. We will provide you with an update by August 8, 2025.


Thank you for your patience and understanding.


Regards,
Bharathi S



NT Nguyen Thinh replied to Bharathi Selvam August 11, 2025 04:03 AM UTC

Any update yet? it is blocking our release schedule


Regards



BS Bharathi Selvam Syncfusion Team August 13, 2025 02:26 PM UTC

Hi Nguyen Thinh,


Thank you for your patience. Upon analysis, we identified that the crash in your sample occurs due to the following project configuration:

 

<AndroidEnableMarshalMethods>true</AndroidEnableMarshalMethods>

 


This is a known .NET MAUI framework-level issue, not specific to the PDF Viewer, and is caused by native Android code execution used within the PDF Viewer control. The same problem has been reported in the .NET Android GitHub repository here:
https://github.com/dotnet/android/issues/9810 


As your project already includes other AOT-related optimizations (<RunAOTCompilation>, <PublishTrimmed>, <TrimMode>, <InvariantGlobalization>), the removal of <AndroidEnableMarshalMethods> will have minimal impact on performance while preventing the crash.

For these reasons, we recommend removing the following line from your project file to resolve the issue:

 

<AndroidEnableMarshalMethods>true</AndroidEnableMarshalMethods>

 


Regards,

Bharathi S


Loader.
Up arrow icon