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> <!– For Android –>-->
<!-- <UseInterpreter>all</UseInterpreter> <!– For iOS, if reflection issues occur –>-->
<Optimize>false</Optimize> <!-- Optional, reduces optimization for easier debugging -->
<!-- <AndroidLinkMode>None</AndroidLinkMode>-->
<!-- Debug config-->
</PropertyGroup>
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:
Regards,
Bharathi S
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
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
Any update yet? it is blocking our release schedule
Regards
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