WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Wrong app sdk version number reported if another application directory with an older app sdk is added to PATH

Open lhak opened this issue 5 months ago • 1 comments

Describe the bug

The Microsoft.Windows.ApplicationModel.WindowsAppRuntime.ReleaseInfo api reports the wrong version number in the following scenario:

  • The app is unpackaged and not self-contained
  • Another application (example: powertoys) is installed and its installation directory is added to the PATH variable and it contains a copy of the app sdk

In this case Microsoft.WindowsAppRuntime.Insights.Resource.dll is loaded from the directory of the other installed application and the wrong version number is reported.

Steps to reproduce the bug

  1. Install powertoys
  2. Create an unpackaged (not self-contained) app sdk application
  3. Check the return value of Microsoft.Windows.ApplicationModel.WindowsAppRuntime.ReleaseInfo

Expected behavior

The app sdk version number should not be influenced by installing another (unrelated) application.

Screenshots

No response

NuGet package version

Windows App SDK 1.8.2: 1.8.251003001

Packaging type

Unpackaged

Windows version

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

IDE

Visual Studio 2022

Additional context

No response

lhak avatar Oct 25 '25 09:10 lhak

This is due to dev\WindowsAppRuntime_Insights\WindowsAppRuntimeInsights.h line 49

        static wil::unique_hmodule LoadResourceModule()
        {
            const PCWSTR c_resourceDllName{ L"Microsoft.WindowsAppRuntime.Insights.Resource.dll" };
            wil::unique_hmodule resourceDllHandle(::LoadLibraryW(c_resourceDllName));
            LOG_LAST_ERROR_IF_NULL_MSG(resourceDllHandle, "Unable to load resource dll. %ls", c_resourceDllName);
            return resourceDllHandle;
        }

LoadLibraryW with a relative filename is probably too broadly permissive here. Probably should be a computed absolute filename as it's expected to be colocated with the calling code in Microsoft.WindowsAppRuntime.dll

P.S. Also should call LoadLibraryExW(..., LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_AS_DATAFILE) as it's a resource-only DLL.

DrusTheAxe avatar Oct 27 '25 06:10 DrusTheAxe