Sam
Sam

Reputation: 30396

.NET MAUI app crashing because it's not loading image file

In my .NET MAUI app, I changed the icons used by the app from font based icons to PNG files and I store these images in Resources > Images folder.

I was able to successfully create a package and upload it to TestFlight but when I try to open the app, it crashes immediately. In crash logs, I see that the cause of crash is that the app was unable to load the PNG file I use for the Flyout i.e. the hamburger menu icon.

The other key change in the app is that it's now a .NET 7 based app.

I thought the publish process would add the PNG images used by the app to the ipa package if I placed them in Resources > Images folder.

Any idea what could be the issue here?

Here are screenshots of exception logs

enter image description here

enter image description here

And here's the MyApp.csproj file:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
        <OutputType>Exe</OutputType>
        <RootNamespace>MyApp</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>

        <!-- Display name -->
        <ApplicationTitle>MyApp</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>com.mycompany.myapp</ApplicationId>
        <ApplicationIdGuid>0636ab8b-e4f3-4c11-83e5-b809594a10b5</ApplicationIdGuid>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.2</ApplicationDisplayVersion>
        <ApplicationVersion>68</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(TargetFramework)'=='net7.0-ios'">
      <CodesignKey>Apple Development: Samuel Uresin (3YQ4LF4U5J)</CodesignKey>
      <CodesignProvision>VS: llc.iquest.ingrid.connect Development</CodesignProvision>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.png" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Splash\splash.png" Color="#262627" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
      <None Remove="Resources\Images\about_graphite.png" />
      <None Remove="Resources\Images\badge_graphite.png" />
      <None Remove="Resources\Images\biz_profile_graphite.png" />
      <None Remove="Resources\Images\coupons_graphite.png" />
      <None Remove="Resources\Images\customers_graphite.png" />
      <None Remove="Resources\Images\dashboard_graphite.png" />
      <None Remove="Resources\Images\feed_graphite.png" />
      <None Remove="Resources\Images\hamburger_manu_graphite.png" />
      <None Remove="Resources\Images\intercom_graphite.png" />
      <None Remove="Resources\Images\plus_graphite.png" />
      <None Remove="Resources\Images\power_graphite.png" />
      <None Remove="Resources\Images\qr_scan_graphite.png" />
      <None Remove="Resources\Images\qr_scan_large_graphite.png" />
      <None Remove="Resources\Images\search_graphite.png" />
      <None Remove="Resources\Images\settings_graphite.png" />
      <None Remove="Resources\Images\shop_graphite.png" />
      <None Remove="Resources\Images\single_user_graphite.png" />
      <None Remove="Resources\Images\subscriptions_graphite.png" />
      <None Remove="Resources\Images\user_profile_graphite.png" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" />
        <PackageReference Include="CommunityToolkit.Maui" Version="3.0.0" />
        <PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
        <PackageReference Include="Ingrid.Aurora" Version="1.5.1" />
        <PackageReference Include="Ingrid.Core" Version="1.5.1" />
        <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
        <PackageReference Include="MonkeyCache.FileStore" Version="1.6.3" />
        <PackageReference Include="Plugin.InAppBilling" Version="6.7.0" />
        <PackageReference Include="Plugin.Maui.Audio" Version="0.1.0-preview1" />
        <PackageReference Include="Sentry.Maui" Version="3.23.1-preview.3" />
        <PackageReference Include="Syncfusion.Maui.Barcode" Version="20.3.56" />
        <PackageReference Include="ZXing.Net.Maui.Controls" Version="0.2.0-preview.2" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
        <PackageReference Include="SQLitePCLRaw.core" Version="2.1.0" />
        <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0" />
        <PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0" />
        <PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0" />
    </ItemGroup>

</Project>

Upvotes: 1

Views: 3071

Answers (1)

Sam
Sam

Reputation: 30396

I was setting the Flyout icon in Styles.xaml and this was the issue -- see below.

<Style TargetType="Shell" ApplyToDerivedTypes="True">
    <Setter Property="Shell.FlyoutIcon" Value="mymenuicon.png" />
</Style>

There's probably a way to set it in Styles.xaml and I'd appreciate it if someone can show me how to do that in the comments.

The fix for my problem was simply setting it in AppShell as follows:

<Shell
   x:Class="MyApp.AppShell"
   FlyoutIcon="mymenuicon.png">
  ...
</Shell>

Upvotes: 2

Related Questions