Skip to content

Conversation

@medhatiwari
Copy link
Contributor

[Mono] Fix ParameterInfo.Name to return null for unnamed parameters

Summary

Fixes runtime inconsistency where Mono's ParameterInfo.Name returns empty string ("") for unnamed parameters while CoreCLR correctly returns null.

Problem

Failing Tests:

  • OpenApiOperationGeneratorTests.ThrowsInvalidOperationExceptionGivenUnnamedParameter
  • RequestDelegateFactoryTests.CreateThrowsInvalidOperationExceptionGivenUnnamedArgument

Root Cause:

// CoreCLR behavior (correct)
var param = lambda.Compile().Method.GetParameters()[0];
param.Name == null  // true

// Mono behavior (bug)
param.Name == ""    //  empty string, not null

ASP.NET Core validation checks if (parameter.Name is null) - this works on CoreCLR but fails on Mono.

Reproduction

using System;
using System.Linq.Expressions;

var unnamed = Expression.Parameter(typeof(int));
var lambda = Expression.Lambda(Expression.Block(), unnamed);
var param = lambda.Compile().Method.GetParameters()[0];

// CoreCLR: param.Name is null 
// Mono: param.Name is "" 
Console.WriteLine($"Name is null: {param.Name is null}");

Test Results:

  • With only loader.c fix: param.Name still returns ""
  • With both fixes: param.Name correctly returns null

Why

ParameterInfo.Name is nullable (string?) per API Contract)

Related Issues

Fixes failures in dotnet/aspnetcore test suite when running on Mono runtime.

cc: @giritrivedi

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 27, 2025
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 27, 2025
@huoyaoyuan huoyaoyuan added area-VM-reflection-mono Reflection issues specific to MonoVM and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 27, 2025
@steveisok steveisok requested a review from BrzVlad October 27, 2025 11:08
@BrzVlad
Copy link
Member

BrzVlad commented Nov 4, 2025

LGTM. Thanks!

@BrzVlad BrzVlad merged commit 6458310 into dotnet:main Nov 4, 2025
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-reflection-mono Reflection issues specific to MonoVM community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants