PolySharp icon indicating copy to clipboard operation
PolySharp copied to clipboard

InternalsVisibleTo from two other projects leads to not being able to use PolySharp

Open cremor opened this issue 1 year ago • 13 comments

Description

If one project references two other projects that both have InternalsVisibleTo to the first project defined, the first project can't use C# features that should be enabled by PolySharp.

Reproduction Steps

  1. Create a new solution with 3 projects using an older .NET version.
  2. Set <LangVersion>11.0</LangVersion> for all projects.
  3. Add PolySharp to all projects.
  4. Try to use a C# 11 feature, e.g. required properties, in all projects. See that it works as expected.
  5. Add a project reference from two projects to the third one.
  6. Add <ItemGroup><InternalsVisibleTo Include="ThirdProjectName" /></ItemGroup> to the referenced projects.

Expected Behavior

Should be able to compile the code.

Actual Behavior

I get compile errors about missing compiler required members.

System info

This section should contain useful info such as:

  • PolySharp NuGet version 1.10.0
  • Operating system version Windows 10 22H2
  • Visual Studio version, or .NET SDK/runtime version VS 17.4.4, SDK 7.0.102, runtime 7.0.2

Additional context

It looks like the compiler error is missleading. The members are not missing, they are there multiple times (so the compiler sees the internal types from both referenced projects). If only one referenced project with InternalsVisibleTo exists then no error happens.

It looks like PolySharp also sees the internal types of the other projects and doesn't generate any additional types. (It only generates the TypeForwards.) But I can actually fix the problem and compile my code when I manually add the required compiler types. Then the compiler doesn't error any more, even though it should then actually see each type 3 times. So maybe the fix for this would be to still generate the required types if the source generator only finds an internal type from another assembly in the current project?

In my actual solution I don't add PolySharp to each project individually but instead use Global Package References. But it seems like this doesn't change anything for this problem.

cremor avatar Jan 17 '23 15:01 cremor