InternalsVisibleTo from two other projects leads to not being able to use PolySharp
See original GitHub issueDescription
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
- Create a new solution with 3 projects using an older .NET version.
- Set
<LangVersion>11.0</LangVersion>
for all projects. - Add PolySharp to all projects.
- Try to use a C# 11 feature, e.g. required properties, in all projects. See that it works as expected.
- Add a project reference from two projects to the third one.
- 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.
Issue Analytics
- State:
- Created 8 months ago
- Reactions:1
- Comments:11
Without knowing anything how PolySharp works internally I see three possible solutions:
PolySharpIncludeGeneratedTypes
). This would allow a fix for my problem without changing anything for existing users. But it would also require other users that have the problem to find that setting and known to enable it to fix this (complicated) problem.Hi, this problem is currently blocking us from using PolySharp in our larger solution. Out of available options I think having a MSBuild flag for “Always generating polyfills” is the best option here?