Skip to content

WinAppSDK 1.8: MRM.cpp's MrmGetFilePathFromName now reports error when the resources.pri file doesn't exist #5814

Closed as duplicate

Description

Describe the bug

Depending on calling context, with WinAppSDK version 1.7, this function used to return "resources.pri" from the current exe path even if that file doesn't exist. Now the function checks for existence and returns ERROR_FILE_NOT_FOUND (https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Core/src/MRM.cpp#L1085) (which seems to contradict the function's documentation BTW).

So this now can break Microsoft.Windows.ApplicationModel.Resources's ResourceManager https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ResourceManager.cpp#L18 in the case this file doesn't exist (which again contradicts ResourceManager 's code comment)

Steps to reproduce the bug

It's in a XAML island (Win32 desktop app hosts .NET + WinUI3 class library) context. There's a full repro project here: https://github.com/smourier/Win32ShowsWinUI3

Uncomment this line to reproduce: https://github.com/smourier/Win32ShowsWinUI3/blob/main/WinUI3ClassLibrary/SampleWindow.xaml.cs#L43

Expected behavior

This should work as before
Maybe there's a workaround

Screenshots

No response

NuGet package version

Windows App SDK 1.8.0: 1.8.250907003

Packaging type

Unpackaged

Windows version

Windows 11 version 24H2 (26100, June 2025 Update)

IDE

Visual Studio 2022

Additional context

No response

Activity

  1. Alovchin91 commented on Sep 13, 2025

    @Alovchin91

    Simon Mourier (@smourier) I think you might be facing the same issue as Yuyi Wang (@Berrysoft) did here: Alovchin91/winui3-rs#5

    I've found a workaround that seems to work in my setup: you need to subscribe to the Application.ResourceManagerRequested event, and offer it a custom ResourceManager instance pointing to the <WinAppSDK_FrameworkPackage>\resources.pri file.

    You can see the Rust example here: Alovchin91/winui3-rs#5 (comment)

  2. Berrysoft commented on Sep 13, 2025

    @Berrysoft
    Contributor

    Alovchin91 I'm afraid that your solution might not work as expected if the user really wants WinUI to read their custom resources file(?)

    Anyway it's a workaround, and MrmGetFilePathFromName is violating its documents here.

  3. smourier commented on Sep 13, 2025

    @smourier
    Author

    @smourier I think you might be facing the same issue as @Berrysoft did here: Alovchin91/winui3-rs#5

    I've found a workaround that seems to work in my setup: you need to subscribe to the Application.ResourceManagerRequested event, and offer it a custom ResourceManager instance pointing to the <WinAppSDK_FrameworkPackage>\resources.pri file.

    You can see the Rust example here: Alovchin91/winui3-rs#5 (comment)

    It's probably the same issue yes. Your workaround the regression seems to work, thanks, but is there a simple way to determine the WinAppSDK's current (loaded) runtime's path from .NET?

    FWIW, this is how I currently do it (and my repo where the initial link points has now this workaround applied):

        private class DummyApp : Application, IXamlMetadataProvider
        {
            public DummyApp()
            {
                ...
                ResourceManagerRequested += (s, e) =>
                {
                    var module = GetModuleHandleW("MRM");
                    var sb = new StringBuilder(1024);
                    _ = GetModuleFileNameW(module, sb, sb.Capacity);
                    var resources = Path.Combine(Path.GetDirectoryName(sb.ToString())!, "resources.pri");
                    e.CustomResourceManager = new ResourceManager(resources);
                };
            }
    
            [DllImport("kernel32", CharSet = CharSet.Unicode)]
            private static extern nint GetModuleHandleW(string lpModuleName);
    
            [DllImport("kernel32", CharSet = CharSet.Unicode)]
            private static extern int GetModuleFileNameW(nint hModule, StringBuilder lpFilename, int nSize);
        }
    
  4. Alovchin91 commented on Sep 13, 2025

    @Alovchin91

    You might want to take a look at an example in the official unpackaged apps deployment documentation: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/deploy-unpackaged-apps#option-2-deploy-windows-app-sdk-runtime-packages-directly

    You should be able to use the PackageManager class methods with Microsoft.WindowsAppSDK.Runtime.Packages.Framework.PackageFamilyName to find the package, and then use one of the Package object's path properties.

  5. smourier commented on Sep 13, 2025

    @smourier
    Author

    Alovchin91 Thanks. I've seen that but it's very complicated, for a runtime which is already loaded and running (in fact it means the bootstrap loader has already ran through this code internally to find the right package, to me they should add some export to this dll so we know what we're really running off), seems really overkill and in the end possibly less safe to me.

  6. Alovchin91 commented on Sep 13, 2025

    @Alovchin91

    Well ideally Microsoft should fix this because it's clearly a bug. But in the meantime seems like this workaround could unblock some people.

  7. beeradmoore commented on Sep 14, 2025

    @beeradmoore

    I think this is the same problem as what is causing #5832 ? As of 1.8 the app no longer produces resources.pri but AppName.pri so the correct one is not loaded. A workaround is to rename AppName.pri to resources.pri on every change to the file, but I'll try that above thing.

    EDIT: I misunderstood what Simon Mourier (@smourier) code above does. That is not the problem I am facing in the update from 1.7 to 1.8.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions