Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create a new WinUI 3 app and target .NET 8 #9539

Closed
wsficke opened this issue Apr 12, 2024 · 5 comments
Closed

Cannot create a new WinUI 3 app and target .NET 8 #9539

wsficke opened this issue Apr 12, 2024 · 5 comments
Labels
area-Tooling bug Something isn't working

Comments

@wsficke
Copy link

wsficke commented Apr 12, 2024

SO X-Post: https://stackoverflow.com/questions/78317988/cannot-create-a-new-winui-3-app-and-target-net-8

Describe the bug

After creating a new WinUI 3 project using the project template, the framework version and nuget references are not current. In this state, targeting .NET 6, the app builds and runs, and you can see the clicky button screen.

The first order of business after executing any project template is to update to the latest framework and packages. With .NET 8, there are documented RID issues that are extern from this SDK. I found a workaround (UseRidGraph) on Stack Overflow to opt out of RID graph pruning, which lets the build pass.

Updating the nuget packages prior to targeting .NET 8 does not change the scenario. The error is introduced when retargeting to .NET 8, not when updating the nuget packages to current.

Build is passing with these props:

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
  <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
  <RootNamespace>Company.Product.Frontend.WinUI</RootNamespace>
  <ApplicationManifest>app.manifest</ApplicationManifest>
  <Platforms>x86;x64;ARM64;</Platforms>
  <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
  <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
  <UseRidGraph>true</UseRidGraph>
  <UseWinUI>true</UseWinUI>
  <EnableMsixTooling>true</EnableMsixTooling>
  <Nullable>enable</Nullable>
</PropertyGroup>

However, when you start the app, you get this error:

Application: Company.Product.Frontend.WinUI.exe
CoreCLR Version: 8.0.424.16909
.NET Version: 8.0.4
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)
   at Company.Product.Frontend.WinUI.Program.Main(String[] args) in C:\Users\me\source\repos\Company.Product\Company.Product.Frontend.WinUI\obj\x64\Release\net8.0-windows10.0.19041.0\win-x64\App.g.i.cs:line 28

Steps to reproduce the bug

  1. Install the SDK and create a new project as documented: https://learn.microsoft.com/en-us/windows/apps/winui/winui3/create-your-first-winui3-app
  2. Upgrade nuget packages to latest version, update target framework to latest version, opt out of RID graph pruning.
  3. Run the application and see the application event log for crash details.

Expected behavior

Windows Apps should run on .NET 8. The developer experience for starting a WinUI 3 project should be world-class and free of frustrating errors and workarounds.

Screenshots

System.DllNotFoundException: 'Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)' @ App.g.i.cs

image

NuGet package version

WinUI 3 - Windows App SDK 1.5.2: 1.5.240404000

Windows version

Windows 11 (22H2): Build 22621

Additional context

Windows Apps should run great on .NET 8. The developer experience for starting a WinUI 3 project should be world-class and free of frustrating errors and workarounds.

Recommend maintaining the project templates to work with latest .NET and NuGet packages out of the box.

@wsficke wsficke added the bug Something isn't working label Apr 12, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Apr 12, 2024
@wsficke wsficke changed the title Cannot create a new WinUI 3 app and target .NET 8.Bug title Cannot create a new WinUI 3 app and target .NET 8 Apr 12, 2024
@DarranRowe
Copy link

That error is curious, it is also an error I do not see. Anyway, to go through the important points.

  1. The projects being out of date is a known issue. The updated project templates that have .NET 8 support can be found here. You cannot build the .vsix file, but there is nothing stopping you from using these files to properly configure a new project. As an example to show this, there is a response to another bug report last month stating that the new project templates are on the way.

  2. If you are using the Windows App SDK 1.5, you really shouldn't need UseRidGraph. A project that I created to test this out works perfectly fine with:

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>CsTest</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;ARM64</Platforms>
    <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
    <PublishProfile>win-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
    <Nullable>enable</Nullable>
  </PropertyGroup>

If you want this to work with all frameworks, then using the method in the project templates will work.

  1. The crash at XamlCheckProcessRequirements basically mean that you do not have the Windows App Runtime referenced. If your application is packaged, then you really need to provide a sample project that exhibits this behaviour since the build system should be picking up the reference from the NuGet package. If your application is unpackaged then you missed a step in the "Create your first WinUI 3 (Windows App SDK) project" link that you provided.
    As per step 7 in the unpackaged section, you need to set WindowsPackageType to none in the .csproj file. This will bootstrap the Windows App Runtime into the process and allow Xaml to work.
    There is an added annoyance here in that using WindowsPackageType set to none will break the packaging for this type of project. There are ways around it if you want the application to work seamlessly packaged or unpackaged.

@wsficke
Copy link
Author

wsficke commented Apr 15, 2024

After rebooting the development machine (ad hoc, just to see if it would help), the project builds and runs on .NET 8 without issues. As others on the GitHub thread have indicated it is not replicable in their existing environments, it seems to me that maybe the documentation should say a restart is required, or the SDK installer should prompt for a reboot?

@codendone codendone added area-Tooling and removed needs-triage Issue needs to be triaged by the area owners labels Apr 25, 2024
@JesseCol
Copy link

Glad to hear you're unblocked! If you come across more detail on what configuration change required a reboot, please let us know. thanks!

@wsficke
Copy link
Author

wsficke commented Apr 26, 2024

It was a fresh installation of WinUI 3 SDK onto a Window 11 development machine with an existing Visual Studio 2022 environment.

@JesseCol
Copy link

JesseCol commented May 1, 2024

Hi again, if anyone else hits this, you might also try uninstalling the WinAppSDK template extension from Visual Studio and then re-installing the latest. If you installed the standalone version from a past download link, it won't be updated in-place.

Thanks!

@JesseCol JesseCol closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Tooling bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants