runtime: Compilation.GetTypeByMetadataName does not account for accessibility
The following code is potentially problematic:
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 to Compilation.GetTypeByMetadataName
outright and provided an alternative that falls back to an accessibility-aware check.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (15 by maintainers)
I believe this can be closed now since #59774 was merged. @danmoseley @mkArtakMSFT I made a new issue in ASP.NET to evaluate.
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.
Reopening because this doesn’t appear to be addressed in the Logging generator. https://github.com/dotnet/runtime/blob/73c0f8d7f6635d589470c7ff7d9680128342aac4/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs#L68-L94