question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 8 months ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
cremorcommented, Jan 19, 2023

Without knowing anything how PolySharp works internally I see three possible solutions:

  • Change PolySharp to generate types which are only available in the current project as an internal type from a different assembly. I think this would be the best solution, unless it has some unexpected negative consequence.
  • Change PolySharp to generate types which are only available in the current project as an internal type from at least two different assemblies. This change would have a smaller impact, but is very specific for my problem. There might be other situations that I’m not thinking of right now which then would not be fixed.
  • Add a new setting to PolySharp that forces it to generate types even if they are available in the current project (similar to 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.
0reactions
martinsuchancommented, Jun 9, 2023

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · Sergio0694/PolySharp
PolySharp provides generated, source-only polyfills for C# language ... InternalsVisibleTo from two other projects leads to not being able to use PolySharp.
Read more >
c# - InternalsVisibleTo does not work
inside my project under test( Properties/AssemblyInfo.cs ) where MyTests is the name of the Unit Test project. But for some reason I still ......
Read more >
Configure InternalsVisibleTo from csproj
Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly. and for more detail follow...
Read more >
bypassing C# visibility rules with Roslyn
Today I wanted to show you how to do something quite cool - how to bypass the type/member visibility rules using the Roslyn...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found