If you get this error and you target only android or ios environment please check your project file and delete this code block.
<!-- Required - WinUI does not yet have buildTransitive for everything -->
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="188.8.131.52" />
Due to a bug we are unable to debug and run WinUI projects in .net 6.0.100 preview 7.21379.14. It was said that the Visual Studio team will fix this with an update. Temporarily, after you deploy your projects, you can run them without debugging by typing the solution name of the start menu.