Skip to content

App crashing when trying to open scanner in release build #207

Open

Description

@hansAtLIS

Hello,
in the project of my company the app currently crashes when trying to open it.
This only happens when the app is build in the relase configuration but works like a charm in debug.
Do you have any idea how to implement the scanner in a different way to stop this behavior?
This is how its implemented as a popup:

<?xml version="1.0" encoding="utf-8" ?>
<local:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:Class="App.Views.Popups.ScannerPopupPage"
                xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
                xmlns:local="clr-namespace:App"
                xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
                xmlns:strings="clr-namespace:App.Resources.Strings"
                Title="{x:Static strings:AppResources.Scanner}">
  <Grid>
    <ContentView x:Name="BarcodeReaderContainer"
                 IsVisible="true">
      <zxing:CameraBarcodeReaderView x:Name="CameraBarcodeReader"
                                     BarcodesDetected="BarcodeDetected"
                                     VerticalOptions="FillAndExpand"
                                     HorizontalOptions="FillAndExpand" />
    </ContentView>


    <BoxView x:Name="UpperGrayedOutSection"
             Style="{StaticResource GrayedOutSection}"
             VerticalOptions="Start" />

    <BoxView x:Name="LowerGrayedOutSection"
             Style="{StaticResource GrayedOutSection}"
             VerticalOptions="End" />

    <BoxView x:Name="redline" IsVisible="true" Style="{StaticResource RedLine}"/>

    <Button x:Name="CloseButton" Style="{StaticResource CloseModalButtonStyle}"
            Clicked="OnCloseButtonClicked" />

    <Button x:Name="FlashlightButton" Style="{StaticResource FlashlightButtonStyle}"
            Clicked="OnFlashlightButtonClicked">

      <Button.ImageSource>
        <FileImageSource File="flashlight.png"></FileImageSource>
      </Button.ImageSource>

    </Button>

    <ImageButton Source="pause_icon"
                 IsVisible="False"
                 x:Name="PlayButton"
                 WidthRequest="100"
                 Clicked="PlayButton_Clicked" />

    <ContentView x:Name="AdditionaleContent"
                 VerticalOptions="End"
                 HorizontalOptions="StartAndExpand"
                 Margin="0,0,0,35" />

    <toolkit:MediaElement x:Name="beepPositive"
                          IsVisible="False"
                          Source="Resources/Sounds/BeepPositive.wav"/>
    <toolkit:MediaElement x:Name="beepNegative" 
                          IsVisible="False"
                          Source="Resources/Sounds/error-sound.wav"/>
  </Grid>

</local:BasePage>

I'll gladly provide additional info if needed.
Best regards,
Hans

Activity

  1. deko139931 commented on Jan 21, 2025

    @deko139931

    I’m facing the same issue. Were you able to resolve it? The app works fine in debugging mode, but when switching to release mode with a distribution certificate and uploading it to TestFlight, it crashes immediately on launch.

  2. olibara commented on Sep 1, 2025

    @olibara

    Same issue today 2025-September-1 with version
    ZXing.Net.Xamarin 3.0.0 and
    ZXing.Net.Mobile 3.1.0_beta2
    Is there Some known fix or turn around ?

  3. jfversluis commented on Sep 1, 2025

    @jfversluis
    Collaborator
  4. olibara commented on Sep 1, 2025

    @olibara
  5. olibara commented on Sep 2, 2025

    @olibara

    Hello Gerald
    I've tried to disable trimming as mentionned
    <PublishTrimmed>false</PublishTrimmed>
    But it gives an error :

    C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.78\tools\Xamarin.Android.Common.targets(523,3): error XA1030:
    The 'RunAOTCompilation' MSBuild property is only supported when trimming is enabled.
    Edit the project file in a text editor to set 'PublishTrimmed' to 'true' for this build configuration.

    I've also tried to remove another property in the csproj

    <TrimMode>full</TrimMode>

    It also gives an error

    Anyway I will try the linker.xml because it is obvious that the issue is coming from the zxing assembly

    I will add this

    <linker>
      <!-- Preserve Zxing assemblies  -->
      <assembly fullname="ZXing.Net.Xamarin" preserve="all" />
    </linker>
    

    And let you know

  6. olibara commented on Sep 3, 2025

    @olibara

    Hello,
    same issue with the Linker explicit directive, in debug it works like a charm but still crash in Release, I will investigate the Logcat details

  7. olibara commented on Sep 7, 2025

    @olibara
  8. olibara commented on Sep 7, 2025

    @olibara

    The issue was indeed due to the linker 👍

    Thanks to Gerald and Jo

    This what need to be added in the csproj

  9. olibara commented on Sep 7, 2025

    @olibara
    <ItemGroup Condition="'$(Configuration)' == 'Release'">
       <TrimmerRootAssembly Include="ZXingNetMobile" RootMode="library" />
     </ItemGroup>
    
  10. jfversluis commented on Sep 12, 2025

    @jfversluis
    Collaborator

    We probably should look at how to make the library trimmer safe, but for now this is a good workaround. Thanks for letting us know!

  11. akhilvswoodplc commented on Dec 3, 2025

    @akhilvswoodplc

    @jfversluis
    Getting this error while adding the workaround
    ILLink : error IL1032: Root assembly 'ZXingNetMobile' could not be found. [{Project}.csproj::TargetFramework=net9.0-ios]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions