WindowsAppSDK: .NET 6 and WINUI3 fails to start Unable to load DLL 'Microsoft.ui.xaml.dll'

Describe the bug

When running WINUI3 on Windows 10 ( 21H1 19043.1083 ) looks like the application never launches, but is application crashes with the below error in the event log

CoreCLR Version: 6.0.21.52210
.NET Version: 6.0.0
Description: The process was terminated due to an unhandled exception.
Exception Info: System.DllNotFoundException: Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

Steps to reproduce the bug

Packaged

  1. Install Windows 10 21H1 19043.1083
  2. Install the latest Microsoft.WindowsAppRuntime.Redist.1.0.0
  3. Install MSIX dependencies
  4. Install application MSIX
  5. Launch the application
  6. Application never launches (well crashes)

Unpackaged,

  1. Install Windows 10 21H1 19043.1083
  2. Install the latest Microsoft.WindowsAppRuntime.Redist.1.0.0
  3. Copy compiled output
  4. Launch the application
  5. Application never launches (well crashes)

Packaged

  1. Install Windows 10 21H2 2200.194
  2. Install the latest Microsoft.WindowsAppRuntime.Redist.1.0.0
  3. Install MSIX dependencies
  4. Install application MSIX
  5. Launch the application
  6. Application never launches (well crashes)

Unpackaged,

  1. Install Windows 10 21H2 2200.194
  2. Install the latest Microsoft.WindowsAppRuntime.Redist.1.0.0
  3. Copy compiled output
  4. Launch the application
  5. Application never launches (well crashes)

Expected behavior

For the application to launch.

Screenshots

No response

IDE

Visual Studio 2022

NuGet package version

Microsoft.WindowsAppSDK 1.0.0-preview3

Project type

  • Packaged
  • Unpackaged

Windows version

Windows 11 (22000), May 2021 Update (19043)

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 16
  • Comments: 63 (3 by maintainers)

Commits related to this issue

Most upvoted comments

If you are trying to run unpackaged version, do not forget to add this code to “csproj” file.

<WindowsPackageType>None</WindowsPackageType>

Microsoft reference

When I run Packaged app on my machine it works. When I run Unpackaged app it doesn’t. When I run exe from console it doesn’t work. When I deploy an app to another machine it doesn’t work. When I say it doesn’t work it means I am getting an error either in Event Viewer or dialog box “Unable to load DLL ‘Microsoft.ui.xaml.dll’ or one of its dependencies” I am running Released version 1.0.0

I just installed VS 2022, and the WindowsAppSDK.Cs.Extension.Dev17.Standalone.vsix

I started a new WinUI3 project form the templates. F5 debug running packaged is ok, but I get this error when I select WinUIDeploy (Unpackaged) . This is trying to start within VS.

has this been resolved? same issue.

I think the problem here is the assumption that you can just xcopy your build output to another PC and run it when you put this in your project file:

<!-- This bundles the .NET Core libraries -->
<SelfContained>true</SelfContained>
<!-- This bundles the WinUI3 components -->
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

I see a few potential fixes for people running into this problem:

  • The app should detect the missing C++ runtime DLLs and throw up a message, or log a message stating the C++ runtime needs to be installed.
  • There should be a nuget package available from Microsoft that allows you to bundle the C++ runtime DLLs with your app.
  • There could be a project file flag that copies the required DLLs to the build directory

Since it still happens now, I wonder why the issue is closed.

In your csproj file, under the <PropertyGroup> tag, try adding: <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

Windows App SDK deployment guide for self-contained apps

Trying to get into WinUI with the new Template Studio for WinUI and this is what I run into right away.

In your csproj file, under the <PropertyGroup> tag, try adding: <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

Windows App SDK deployment guide for self-contained apps

Thanks @dshe , i would never have figured this out.

I’m investigating WinUI 3 for future projects and a POC, after 2 hours wasted on something silly, i am seriously considering ditching it. Appears to need serious time to mature.

I recently install visual studio 2022 and testing maui app with windows and I getting this error. All solutions proposed above has been done, but error persists

image

@MikeHillberg Ping on this - I’m getting the same issue with 1.0.1.

I had to change this in the .wapproj,

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

When I try this the code doesn’t compile because it is now missing all xaml references. For example, Application and Window are no longer found.

I’ve seen that when the VCRedist wasn’t installed on the target machine, which would explain why you don’t see it on a machine with VS installed. Xaml.dll is generally the first runtime DLL to get loaded (trying to get static APIs from the Application class), so multiple install issues can show up with that message.

I’m still having the same problem, also after reinstalling VCredist 14.30.30704.

If you are trying to run unpackaged version, do not forget to add this code to “csproj” file.

<WindowsPackageType>None</WindowsPackageType>

Microsoft reference

Today is December 19, 2023, and I still got the System.DllNotFoundException error after creating a barebone new app with the template: image

This solution from Jan 20, 2022 still saved me.

https://nicksnettravels.builttoroam.com/packaged-unpackaged-self-contained/ This Link has the answer that helped me. It was a life saver.

The blog above shared this:

The main thing is you want to run your application as unpackaged. Do these two things first

  1. Add a property to the csproj file for your application, <WindowsPackageType>None</WindowsPackageType>' under the '<PropertyGroup> tag
  2. Remove the package.appxmanifest file from your project
  3. Run the Application as Unpackaged

Ditto to @myokeeh I am in the same bucket. Running the project packaged fails to run with VS reporting “The project doesn’t know how to run the profile {insert profile name here} (Package)” [ it actually lists the profile name in between the curly brackets ] and running unpackaged results in “System.DllNotFoundException: ‘Unable to load DLL ‘Microsoft.ui.xaml.dll’ or one of its dependencies: The specified module could not be found. (0x8007007E)’”. Both tries had x86 and Debug set (that was the default when I created the project using the new Template Studio extension.

I’ve tried to make that argument many times. It’s how all the other packaged app projects work. No idea why WinUI needed to be different but I agree its a serious developer experience flaw that has hurt so many people getting started.

I’m getting the same problem on 1.0.2 also today. Is there any known workarounds until this is resolved?

@candritzky I had the same issues on Windows 10 version 1909 and installing the VC++ runtime didn’t fix it. I copied the following DLLs from my dev PC to my apps directory on the target PC and it worked. They might not all be required though: concrt140.dll msvcp140.dll msvcp140_1.dll msvcp140_2.dll msvcp140_atomic_wait.dll msvcp140_codecvt_ids.dll vcruntime140.dll vcruntime140_1.dll

@kaptainkev You saved my day! Thank you so much for sharing this!

I experienced this issue with a PC running within Visual Studio 2022 17.2.1 on Win 10 1909 (18363.2094) with all of the appropriate packages installed, as per this thread.

The target version OS version in the project was 10.0.19041.0. I changed that to 10.0.18362.0 and the project ran successfully.

We are also having this issue. Reinstalling VCRedist didn’t help, nor did any of the other suggestions above. We also recreated the issue by creating a new WinAppSDK packaged app, publishing/installing/executing it. We also attempted to change the TargetFramework from net6.0xxx to net5.0xxx but continued to receive the error.

I’m getting the same problem on 1.0.1 as well. Any timeline on when it’ll be resolved/fixed?