`Microsoft.ui.xaml.dll` is unable to load
Asked Answered
O

5

17

I am getting an exception in my WinUI3 app that Microsoft.ui.xaml.dll is unable to load. I have included Microsoft.UI.Xaml and Microsoft.Graphics.Win2D in nuget.

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
  Source=TibraUI
  StackTrace:
   at TibraUI.Program.XamlCheckProcessRequirements()
   at TibraUI.Program.Main(String[] args) in C:\Users\Bryan\src\tibra\Tibra\TibraUI\obj\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.g.i.cs:line 28

Windows Version 21H1 Build 19043.1348

My App.xaml

<Application
    x:Class="TibraUI.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TibraUI">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                <!-- Other merged dictionaries here -->
            </ResourceDictionary.MergedDictionaries>
            <!-- Other app resources here -->
        </ResourceDictionary>
    </Application.Resources>
</Application>
Okra answered 24/11, 2021 at 17:47 Comment(6)
github.com/microsoft/WindowsAppSDK/issues/1762Taber
FWIW I am seeing the same error and the link provided by Hans refers to a now closed thread that does not offer a solution - the suggested install of the VC redist does not work for me.Exsiccate
A solution that seemed to work for me was to select the template with two projects, i.e. the one with the separate packager project (WAP). As long as you have the packager project selected as startup project, it seems to work. Setting the 'real' project as startup results in the same error. Mind you you have to set your machine to developer mode.Exsiccate
@Exsiccate That didn't work for me unfortunatelyOkra
@Okra sorry to hear that. I am completely new to this so have very little to offer you. I created a new working boilerplate WinUI3 project and put in on GitHub, perhaps browsing that code or cloning it may give you some insights. github.com/arnovb-github/EmptyWinUIExsiccate
Had the same error, in my case it occurred when trying to create & run an unpackaged winui3 app. It was fixed by adding the following property to the project file: <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>Destroy
L
21

Run the package as the startup project. It's not intuitive, but the main project is not meant to run.

This answer only applies to those who created a project that included a package project.

Leal answered 13/12, 2021 at 20:30 Comment(4)
How do I do this?Okra
I only have one projectDehumidifier
Are you sure, maybe there is another entry in your solution "{project name} (Package)"? If yes, try to start this one.Swaine
Yep that was it. Just set the package project as the startup project and hit run. You will see in the progress bar of vs it "deploy",Apace
M
16

In the app project file, inside the main PropertyGroup, add <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> as shown below.

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>EPicker</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;arm64</Platforms>
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>

Malaysia answered 27/10, 2022 at 6:15 Comment(2)
Well, ok, this fixes the app startup, but breaks other stuff. (Why is WinUI3 so buggy 😪)Cateyed
This fixed it for me as well!! Kept getting Windows.UI.Xaml can't be loaded as an error in event viewer.Schnitzel
M
1

I was able to solve the issue in the following way:

I created a Uno WinUI 3 .NET 6 project using dotnet new unoapp-winui-net6 from the command prompt. I had to update the Windows.Desktop.csproj reference from:

<ItemGroup> 
    <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.18362.16" /> 
    <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.18362.16" /> 
</ItemGroup> 

to:

<ItemGroup>
    <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.19041.22" />
    <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.19041.22" />
</ItemGroup>

and in the Windows.Package.wapproj, I updated

<ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="[1.0.0-experimental1]">
        <IncludeAssets>build</IncludeAssets>
    </PackageReference>
</ItemGroup>

to

<ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="[1.0.0]">
        <IncludeAssets>build</IncludeAssets>
    </PackageReference>
</ItemGroup>

(see also https://github.com/unoplatform/uno/discussions/7617)

In the Configuration Manager in Visual Studio 2022 Preview 1.1, I then had to change the platform for Windows.Desktop to x64 (was x86). Windows.package should also be x64.

I set the Windows.Package project as the startup project. I could build and start the application without the error.

Malti answered 20/12, 2021 at 11:56 Comment(0)
A
1

Issue is resolved adding a launchSettings.json with:

{
  "profiles": {
    "Windows Machine": {
      "commandName": "MsixPackage",
      "nativeDebugging": false
    }
  }
}
Austronesia answered 29/10, 2022 at 0:53 Comment(1)
Worked for me, thanks! Strangely enough, I deleted this file and managed to run the app via IDE with no problems for a few hours. Then, 5 days later, I return to the project and the error pops up. Huh. Maybe it's the .vs cache or something.Garrity
B
1

I solve my problem for "Blank App, Packaged with WAP (WinUI 3 in Desktop)". I need to build both packages:

  • "signed package"
  • "unsigned lunch app via .exe".

By default you can build only signed packaged. But simply add <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> into csproj in app project, not in Package project. Now you can build app that launch via .exe. When you need build signed package, just comment WindowsAppSDKSelfContained.

Full .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>ButLoaderWin32</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;ARM64</Platforms>
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <UseWinUI>true</UseWinUI>
    <!-- comment WindowsAppSDKSelfContained if you want packaged app for WinStore, uncomment if you want unpackaged app without certification-->
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230602002" />
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
    <Manifest Include="$(ApplicationManifest)" />
  </ItemGroup>
</Project>
Begga answered 5/7, 2023 at 9:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.