Skip to content

ms-appx URIs with a query string or fragment don't resolve #24448

Open

Description

@MartinZikmund

Current behavior

ms-appx URIs that carry a query string or fragment don't resolve to their asset. StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/logo.png?v=2")) fails on every target.

Each platform builds the lookup path from uri.PathAndQuery and passes it through verbatim:

  • src/Uno.WinRT/Storage/StorageFile.skia.cs:25
  • src/Uno.WinRT/Storage/StorageFile.UIKit.cs:21
  • src/Uno.WinRT/Storage/StorageFile.wasm.cs:24
  • src/Uno.WinRT/Storage/StorageFile.Android.cs:38

So the code looks for a file literally named logo.png?v=2, which doesn't exist.

Android used to be an accidental exception. Its drawable lookup ran the encoded name through Path.GetFileNameWithoutExtension, and Path.GetExtension("logo.png?v=2") returns .png?v=2, so the entire query was stripped along with the extension and the lookup landed on Assets_logo. The Android asset fallback (assets.Open(path)) still failed. That coincidence no longer holds after #15891, which resolves the drawable resource name directly instead of deriving it by trimming an extension.

Expected behavior

A query string or fragment is not part of an asset's identity, so it should be stripped before the path is resolved, consistently on all targets.

How to reproduce it (as minimally and precisely as possible)

var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/logo.png?v=2"));

Workaround

Drop the query string from the URI.

Works on UWP/WinUI

Unverified - worth confirming what WinUI does with a query on ms-appx before settling on the behavior.

Anything else we need to know?

The fix belongs in GetFileFromApplicationUri rather than in AndroidResourceNameEncoder, so that every platform behaves the same. Using uri.AbsolutePath in place of uri.PathAndQuery is the likely shape of it, and it should come with coverage for at least one non-Android target. Raised from review feedback on #15891.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions