overview

I recently ran into compiler warning cs0436 while working on a solution with a shared project in VS2022. If you run into the same, this might help you troubleshoot.

scenario

You’re working on a solution that contains a project, alpha (which is also the name of its namspace). That project contains a project reference to another project, bravo:

alpha
  |--bravo

Shared project, charlie, contains code that is used by alpha, bravo, and other projects. Because of this, a shared project reference from bravo to charlie already exists. You also add a shared project reference from alpha to charlie:

alpha
  |--bravo
  |----|--charlie

problem

If the references to charlie were project-to-project references, there would be no issue. In such a case, charlie is essentially a portable class library and Visual Studio references its DLL. However, charlie is a shared project, which means its code is compiled into the executable project (alpha and/or bravo) just as if it were included natively in that project. This now result in a cs-0436 that reads:

The type ‘SomeType’ in ‘alpha’ conflicts with the imported type ‘SomeType2’ in ‘alpha’. Using the type defined in ‘alpha’.


Since bravo references charlie, it imports charlies types. Since alpha also references charlie, it imports charlies types twice: once directly from charlie and once through its reference to bravo.

solution

The solution is simple: remove the shared project reference from alpha to charlie. Code in alpha that needs types in charlie need simply include a using statement:

using charlie

The final reference map should then look like this:

alpha
  |--bravo
       |--charlie