microsoft / microsoft/WindowsAppSDK

[Dynamic Dependencies] WinUI 2 fails to load resources

Open
#3,242 10 comments 1 reaction 1 assignee Claimed by @MikeHillberg View on GitHub
area-WinUI
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

When using Windows App SDK Dynamic Dependencies (`MddTryCreatePackageDependency` and `MddAddPackageDependency`), WinUI 2 isn't able to load the appropriate resources.
```
onecoreuap\base\mrt\runtime\com\dllsrv\mrtresourcemanager.cpp(228)\MrmCoreR.dll!00007FF86B9A2009: (caller: 00007FF869CC9435) ReturnHr(22) tid(c0) 80073B1F ResourceMap Not Found.
Exception thrown at 0x00007FF87DC1E1FC (KernelBase.dll) in XamlIslandsApplication.exe: WinRT originate error - 0x80004005 : 'Cannot locate resource from 'ms-appx://Microsoft.UI.Xaml.2.7/Microsoft.UI.Xaml/Themes/21h1_themeresources.xaml'.'.
```

### Steps to reproduce the bug

Problematic code:
```cpp
void RegisterPackageDependency(LPCWSTR packageFamilyName, PACKAGE_VERSION minVersion)
{
MddPackageDependencyProcessorArchitectures arch;
#if defined(_M_X64)
arch = MddPackageDependencyProcessorArchitectures::X64;
#elif defined(_M_ARM64)
arch = MddPackageDependencyProcessorArchitectures::Arm64;
#elif defined(_M_IX86)
arch = MddPackageDependencyProcessorArchitectures::X86;
#endif

PWSTR dependencyId, discardedPfn;
MDD_PACKAGEDEPENDENCY_CONTEXT discardedContext;
MddTryCreatePackageDependency(NULL, packageFamilyName, minVersion, arch, MddPackageDependencyLifetimeKind::Process, NULL, MddCreatePackageDependencyOptions::None, &dependencyId);
// Give a higher rank so that our packages are prioritized over Windows App SDK.
MddAddPackageDependency(dependencyId, -1, MddAddPackageDependencyOptions::None, &discardedContext, &discardedPfn);
}

MddBootstrapInitialize(::Microsoft::WindowsAppSDK::Release::MajorMinor, ::Microsoft::WindowsAppSDK::Release::VersionTag, PACKAGE_VERSION{});

RegisterPackageDependency(L"Microsoft.VCLibs.140.00_8wekyb3d8bbwe", PACKAGE_VERSION{
.Revision = 0,
.Build = 30704,
.Minor = 0,
.Major = 14
});

RegisterPackageDependency(L"Microsoft.UI.Xaml.2.7_8wekyb3d8bbwe", PACKAGE_VERSION{
.Revision = 0,
.Build = 13004,
.Minor = 2109,
.Major = 7
});

xamlApp = ::winrt::Microsoft::Toolkit::Win32::UI::XamlHost::XamlApplication({ winrt::Microsoft::UI::Xaml::XamlTypeInfo::XamlControlsXamlMetaDataProvider() });
auto test = winrt::Microsoft::UI::Xaml::Controls::XamlControlsResources{}; // fails here
```

Project configuration:
1. Requires Microsoft.UI.Xaml 2.7, Microsoft.WindowsAppSDK and Microsoft.Toolkit.Win32.UI.XamlApplication
2. Add these lines to a `PropertyGroup`:
```xml

$(BeforeLinkTargets);
_UnpackagedWin32GenerateAdditionalWinmdManifests;

```
3. Add these targets
```xml


<_WinUI3Reference Include="@(Reference)" Condition="'%(Filename)' == 'Microsoft.WinUI' OR ($([System.String]::Copy('%(FullPath)').ToLowerInvariant().Contains('windowsappsdk')) AND %(Filename) == 'Microsoft.UI.Xaml')" />







<_UnpackagedWin32WinmdManifest Include="@(ReferencePath->'$(IntDir)\%(FileName).manifest')" Condition="'%(ReferencePath.IsSystemReference)' != 'true' and '%(ReferencePath.WinMDFile)' == 'true' and '%(ReferencePath.ReferenceSourceTarget)' == 'ResolveAssemblyReference' and '%(ReferencePath.Implementation)' != ''">
%(ReferencePath.FullPath)
%(ReferencePath.Implementation)


<_UnpackagedWin32WinmdProjectReference Condition="'%(_ResolvedNativeProjectReferencePaths.ProjectType)' != 'StaticLibrary'" Include="@(_ResolvedNativeProjectReferencePaths->WithMetadataValue('FileType','winmd')->'%(RootDir)%(Directory)%(TargetPath)')" />
<_UnpackagedWin32WinmdManifest Include="@(_UnpackagedWin32WinmdProjectReference->'$(IntDir)\%(FileName).manifest')">
%(Identity)












```

### Expected behavior

WinUI 2 should be able to find the resources.

### Screenshots

_No response_

### NuGet package version

Windows App SDK 1.2.1: 1.2.221116.1

### Packaging type

Unpackaged

### Windows version

Insider Build (xxxxx)

### IDE

Visual Studio 2022-preview

### Additional context

Using Windows 11 Dynamic Dependencies (`TryCreatePackageDependency` and `AddPackageDependency`) doesn't cause this problem.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.