-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.ReflectionquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Description
Consider the following console app:
using System;
using System.Reflection;
Type type = Assembly.GetExecutingAssembly().GetType("System.Runtime.CompilerServices.NullableContextAttribute")!;
ParameterInfo parameterInfo = type.GetConstructor(new Type[] { typeof(byte) })!.GetParameters()[0];
Console.WriteLine(parameterInfo.Name is not null); // Expected "P_0", got null
// Force generation of a NullableContextAttribute in this assembly
static string? MethodWithNullableAnnotations() => throw new NotImplementedException();
// Generated attribute:
//
//[CompilerGenerated]
//[Microsoft.CodeAnalysis.Embedded]
//[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
//internal sealed class NullableContextAttribute : Attribute
//{
// public readonly byte Flag;
// public NullableContextAttribute(byte P_0)
// {
// Flag = P_0;
// }
//}I'm not sure if this is a bug or not, but I would have expected parameterInfo.Name to be non-null in this case. The issue does not reproduce if I manually define the attribute as decompiled. Documentation for ParameterInfo.Name seems to suggest that Name can be null if the parameter is obtained via MethodInfo.ReturnParameter but this is not the case in this reproduction. Can reproduce the same behavior in both .NET 7 and netfx runtimes.
Discovered while investigating #58690.
Metadata
Metadata
Assignees
Labels
area-System.ReflectionquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.