'Unable to add a reference to project - UWP to Class Library project?

A WPF project and a UWP project share the same solution. Can both projects reference a common project?

  • "Common" - .NET 6 target framework, class library
  • "UWP" - targets Windows 10 Creators Update (Build 15063)
  • "WPF App" - .NET 6 target framework, references "WPF2"
  • "WPF2" - .NET 6 target framework

The "WPF" project can reference "Common" no problem, but the "UWP" project says "Unable to add a reference to project 'Common'".

unable to add a reference

Annoyingly, the error message does not give a reason why.

How to use a class from one C# project with another C# project

Common controls for UWP and WPF

Reference a class library from UWP and ASP.NET 5 (solution here)



Solution 1:[1]

UWP is not compatible with .NET Core or .NET 6.

If you want to share code between a WPF app and a UWP app, your shared project should target .NET Standard 2.0.

Please refer to the docs for more information about .NET Standard and the supported .NET implementations for each version.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1