Search code examples
.netwpfvisual-studio.net-8.0

How to fix errors after updating WPF app to .NET 8


I am attempting to update a WPF app from .NET Framework 4.7.2 to .NET 8. Using the Upgrade option in Visual Studio, I have updated all of my projects and resolved my dependencies.

What I can't figure out is why I am getting several errors that look like this:

  • XamlC error XFC0000: Cannot resolve type "Application".
  • XamlC error XFC0000: Cannot resolve type "Window".
  • XamlC error XFC0000: Cannot resolve type "UserControl".

Googling this brings back results for .NET Maui an Xamarin, I don't think either of these apply to me.

How do I fix these errors? Am I missing something?


Solution

  • Converting a WPF project from .NET Framework to .NET Core/6/7/8/etc. can be a little tricky because while the code and XAML shouldn't need changes, the project files are completely different as are the output files.

    If having any trouble making the conversion (whether manual or automated), these would be the standard troubleshooting steps to try:

    1. Clear out all bin/obj directories and the hidden .vs directory(s) and restart VS.
    2. Ensure the right tooling is installed in Visual Studio. The ".NET desktop development" workload is required and should be sufficient.
    3. Ensure that every relevant csproj file has the <UseWPF>true</UseWPF> property in addition to <TargetFramework>netX.0-windows</TargetFramework>.
    4. If your .NET Core WPF csproj files started as .NET Framework projects, it's quite possible either you or the conversion tool missed items that were specific to .NET Framework and no longer apply to .NET Core. The .NET Framework project files were a lot more verbose and bespoke to the platform, so there may be obsolete leftover items in there that are interfering with the build.
    5. Not directly part of the question, but worth mentioning - when distributing your app, don't forget your users will either need the .NET Windows Desktop runtime, or you'll need to publish your app with the "self-contained" deployment mode so that all needed runtime assemblies are included (which unfortunately adds on the order of 100MB to your distribution size). This wasn't an issue with .NET Framework because WPF was a standard part of the Framework and Framework was almost always already installed on newer Windows machines.