UWP error UA306_A2 occuers after WPF project(.Net Framework4.8) port to .Net6

Skye Yuan 1 Reputation point
2022-09-16T08:17:59.783+00:00

Hi,

I have a WPF Project(.Net Framework4.8), and after I port it to .Net6, the project built failed and I got below error:
UA306_A2 UWP CoreDispatcher : Windows.UI.Core.CoreDispatcher is no longer supported. Use DispatcherQueue instead. Read: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/threading

The error comes from below source code:
var d = System.Windows.Threading.Dispatcher.CurrentDispatcher;

My question is that my project is not a UWP project,why did I got this error.

By the way,here are some supplements:

  1. I used VS2022.
  2. I create a new blank WPF project with VS 2017,and add the source code.
    After porting to .net6,the UA306_A2 still exist,but its type is warning and the project could build successfully.

I want to know how to solve the UA306_A2 error with my project?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,674 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,264 questions
{count} votes