Packaged .Net Core app that uses XAML Host not building? It's a known issue - here's how to fix it.

The XAML Host is a powerful control that allows you to easily use UWP and WinUI 2 controls in a non-UWP application using the XAML Islands feature introduced in Windows 10 1903. Many Microsoft applications use XAML Islands, such as Notepad, Paint, Windows Terminal, the Windows Taskbar, Magnifier, File Explorer and more. Many of our applications using XAML Islands as well such as Codly, LaserCursor, KeepOn, QPad and more. The advantage of XAML Islands, is that you can use modern controls in a non-UWP application, allowing for various things such as better touch support and dark mode support. The XAML Host control makes using XAML Islands in .Net Core and .Net Framework applications easy. Unfortunately, there's an issue with newer versions of Visual Studio 2019 and all versions of Visual Studio 2022 that can prevent packaged applications that use the XAML Host not to build.

About the issue

If you follow Microsoft's documentation for a packaged app in 'Use XAML Islands to host a UWP XAML control in a C# WPF app' or do something similar in Visual Studio 2022 or a newer version of Visual Studio 2019, you might find that it doesn't build. You may receive error messages about duplicates such as the following:

• Validation error. error 80080204: App manifest validation error: Line 217, Column 27, Reason: The field "[local-name()='Extensions']/[local-name()='Extension']/[local-name()='InProcessServer']/[local-name()='ActivatableClass']" with value "Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication" must only be declared once. A duplicate exists on Line 42, Column 27.
• PRI175: 0x80073b0f - Processing Resources failed with error: Duplicate Entry.
• PRI222: 0x80073b0f - Unspecified error occurred.

Luckily, this didn't use to be an issue and doesn't occur in Visual Studio 2019 version 16.9.8 and Microsoft allows downloading older versions of Visual Studio and you can keep using the latest version of Visual Studio 2022 alongside an older version of 2019.

Downgrading Visual Studio

In order to install an older version of a specific Visual Studio product, such as Microsoft Visual Studio Community 2019, you must first uninstall the existing version of that product, if it exists. Don't worry about any other Visual Studio products installed except for the one you want to downgrade. For example, if you have Microsoft Visual Studio Community 2019 and Microsoft Visual Studio Community 2022, you don't need to uninstall Microsoft Visual Studio Community 2022 in order to downgrade to an older version of Microsoft Visual Studio Community 2019 - the two versions are independent of each other.

So basically, if you have a version of Visual Studio 2019 installed, uninstall it first before downgrading. There's no need to uninstall Visual Studio 2022 if you have it - it won't interfere so you can use the latest version of Visual Studio 2022 without any issues.

Where to download old versions of Visual Studio 2019

You can download old versions of Visual Studio 2019 here: https://learn.microsoft.com/en-us/visualstudio/releases/2019/history. Scroll down to the table under 'Release Dates and Build numbers' and find version 16.9.8 and download the appropriate version. Then run the installer to install it.

Tip: Downgrading the Community version of Visual Studio 2019? You may not see a link for it there, but you can still downgrade it. First, download the Professional version. Then run the installer you just downloaded. Once the Workloads screen appears, click the x up the top right to cancel it as shown in the following screenshot:



Once you cancel that, select the 'Available' tab:


You should be shown a screen that allows you to choose which version of Visual Studio 2019 to install. From here, just select the Community version of 2019.

After downgrading

Now that you've downgraded, open up the version of Visual Studio 2019 that you just downgraded and try and build your project again - it should now work! If you still get similar errors, you can try right clicking on the solution and select 'Clean' and once that's done, try right clicking on the solution and clicking 'Rebuild'. You can also try deleting the 'obj' and 'bin' folders in the projects you're trying to build.

Help get this fixed

Unfortunately, this issue still hasn't been fixed. You can help bring attention to Microsoft about this issue as well as discuss it with other users in the various places it has been reported. See the following links for places where this issue has been reported:


Did you have this issue? Did this article help you? Did you follow the steps in this article but still have the issue? Do you have any other workarounds for this issue? Let us know in the comments!

Comments

Popular posts from this blog

How to show placeholder text in a WPF TextBox in C# and VB

How to enable dark title bar in WPF and Windows Forms/WinForms apps in C# and VB

How to use modern icons in XAML in WPF on Windows 10 and 11

How to change the colour of a WPF or Windows Forms/WinForms title bar in Windows 11 in C# and VB

Microsoft WebView2: How to check if the WebView2 runtime is installed in C# and VB