-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compilation.GetTypeByMetadataName does not account for accessibility #57349
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsThe following code is potentially problematic: runtime/src/libraries/System.Text.Json/gen/Reflection/MetadataLoadContextInternal.cs Line 26 in c8a658c
If any assembly referenced by the compilation defines a second copy of a type as See also dotnet/roslyn#52399
|
Removing @layomia assignment as he is out at the moment. We need to make this fix for 6.0 as it would be a blocker for source generator usage. |
@sharwell is the recommendation to copy the extension file and use it locally? I don't see a public (shipping) API. For STJ,
|
Fixed for 6.0 in #58766. |
@layomia @maryamariyan was this fixed in the logging generator as well? If not, do we have an issue tracking that? |
Reopening because this doesn't appear to be addressed in the Logging generator. runtime/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs Lines 68 to 94 in 73c0f8d
|
Tagging subscribers to this area: @maryamariyan Issue DetailsThe following code is potentially problematic: runtime/src/libraries/System.Text.Json/gen/Reflection/MetadataLoadContextInternal.cs Line 26 in c8a658c
If any assembly referenced by the compilation defines a second copy of a type as See also dotnet/roslyn#52399
|
@sharwell this appears to only affect framework types that are redefined\cross-compiled, and not user-defined types since conflicts appear to be avoided by selecting the type in the first referenced assembly, whether the Type is Since System.Text.Json resolves many internal types (all supported collection types and unsupported types) it makes sense to do that just in case. However, for other generators that use
|
Actually the collection and unsupported types are not affected by usage of |
I would typically use the alternative method everywhere. I can't think of a downside of this, and it's the approach used by dotnet/roslyn-analyzers. |
I bet @jaredpar can think of cases to counter this. Wouldn't be surprised if they are in our own codebases :) |
The way I usually frame this is:
That is essentially the situation you can get into here. In some ways it's not completely unreasonable. For instance do we want to bend over backwards to support libraries that redefine I just want to make sure that the consequences and impact of the decisions is understood 😄 |
@mkArtakMSFT are there issues in ASP.NET's usage? https://grep.app/search?current=2&q=GetTypeByMetadataName&filter[repo][0]=dotnet/aspnetcore |
ping @mkArtakMSFT 😄 |
I believe this can be closed now since #59774 was merged. @danmoseley @mkArtakMSFT I made a new issue in ASP.NET to evaluate. |
The following code is potentially problematic:
runtime/src/libraries/System.Text.Json/gen/Reflection/MetadataLoadContextInternal.cs
Line 26 in c8a658c
If any assembly referenced by the compilation defines a second copy of a type as
internal
(e.g. how Microsoft.CodeAnalysis defines its own copy of the nullable attributes),GetTypeByMetadataName
will return null for that type even if only one copy is accessible to the compilation. The problem occurred enough times that dotnet/roslyn-analyzers banned direct calls toCompilation.GetTypeByMetadataName
outright and provided an alternative that falls back to an accessibility-aware check.See also dotnet/roslyn#52399
The text was updated successfully, but these errors were encountered: