Wrong app sdk version number reported if another application directory with an older app sdk is added to PATH
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
- Install powertoys
- Create an unpackaged (not self-contained) app sdk application
- 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
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.