Skip to content

Microsoft.Maui.Controls.ImageSource.FromFile fails in iOS when image in subfolder #22887

@munkii

Description

@munkii

Description

We have some PNGs that we display via a ViewModel. The property on the ViewModel is an ImageSource

Most of the images live directly under Resources/Images but some are in a subfolder called "signal". All the images have the Build Action of MauiImage

In the ViewModel we load those images into the ImageSource like this:

this.Image = Microsoft.Maui.Controls.ImageSource.FromFile("signal/red_hexagon1.png");

In Android this works fine. In iOS it does not work and we see the following error message in the Output window

[0:] Microsoft.Maui.FileImageSourceService: Warning: Unable to load image file 'Signal/red_hexagon.png'.

System.InvalidOperationException: Unable to load image file.
at Microsoft.Maui.FileImageSourceService.GetImageAsync(IFileImageSource imageSource, Single scale, CancellationToken cancellationToken)

If I move the image into root of "Resources/Images" the image loads fine.

This fails on both the Device (iOS 17.4.1) and Simulator (iPhone 15 iOS 17.4)

It works fine on Android

Steps to Reproduce

Call Microsoft.Maui.Controls.ImageSource.FromFile on iOS with an Image in a sub folder of Resources/Images

Link to public reproduction project repository

No response

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17.4.x

Did you find any workaround?

Move image to the root.

Relevant log output

[0:] Microsoft.Maui.FileImageSourceService: Warning: Unable to load image file 'Signal/red_hexagon.png'.

System.InvalidOperationException: Unable to load image file.
   at Microsoft.Maui.FileImageSourceService.GetImageAsync(IFileImageSource imageSource, Single scale, CancellationToken cancellationToken)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-imageImage loading, sources, cachingpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions