Skip to content

ResourceLoader.GetString throws COMException (NamedResource Not Found) for keys containing '.' in WinUI 3 desktop app #6247

@hoshiizumiya

Description

@hoshiizumiya

Describe the bug

When calling:

var loader = new ResourceLoader();
var value = loader.GetString("XXXXX.Common.Yes");

a COMException is thrown:

NamedResource Not Found.

The resource key does exist in Resources.resw.

If the key is changed from:

XXXXX.Common.Yes

to:

XXXXX_Common_Yes

the lookup succeeds immediately.

This indicates that resource keys containing . may not be resolved correctly by ResourceLoader.GetString.

The exception originates from WinRT resource lookup and is reported by Visual Studio at throw time (even if later caught).

API reference:
https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.windows.applicationmodel.resources.resourceloader.getstring
https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ResourceLoader.cpp

Steps to reproduce the bug

Create a new WinUI 3 Desktop project (C#/C++).

Add a string resource in Resources.resw:

Name: XXXXX.Common.Yes
Value: Yes

Call:

var loader = new ResourceLoader();
var value = loader.GetString("XXXXX.Common.Yes");

Observe that COMException (NamedResource Not Found) is thrown.

Change the key to:

XXXXX_Common_Yes

Update the code accordingly and rerun.

Observe that the lookup succeeds.

Expected behavior

WinUI 3 (via Windows App SDK)

Desktop application

Note: This behavior was observed in a desktop project. Packaged vs. unpackaged scenarios have not been independently verified, so no conclusion is made regarding packaging impact.

Screenshots

Image Image

NuGet package version

Windows App SDK 1.8.5: 1.8.260209005

Packaging type

Unpackaged

Windows version

Insider Build (xxxxx)

IDE

No response

Additional context

Replacing . with _ consistently resolves the issue.

This may relate to URI fragment semantics or MRT/PRI key normalization.

Clarification would be appreciated on whether . is officially supported in resource keys for ResourceLoader.GetString.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions