Consider the following console app:
usingSystem;usingSystem.Reflection;Typetype=Assembly.GetExecutingAssembly().GetType("System.Runtime.CompilerServices.NullableContextAttribute")!;ParameterInfoparameterInfo=type.GetConstructor(newType[]{typeof(byte)})!.GetParameters()[0];Console.WriteLine(parameterInfo.Nameis not null);// Expected "P_0", got null// Force generation of a NullableContextAttribute in this assemblystaticstring?MethodWithNullableAnnotations()=>thrownewNotImplementedException();// 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.
Consider the following console app:
I'm not sure if this is a bug or not, but I would have expected
parameterInfo.Nameto be non-null in this case. The issue does not reproduce if I manually define the attribute as decompiled. Documentation forParameterInfo.Nameseems to suggest thatNamecan 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.