Skip to content

Min API validation extracts bad display name from DisplayAttribute #61589

Open
@sbomer

Description

@sbomer

For members with DisplayAttribute, this logic extracts the first named argument and uses it as the display name:

if (displayNameAttribute.ConstructorArguments.Length > 0)
{
return displayNameAttribute.ConstructorArguments[0].Value?.ToString() ?? property.Name;
}
else if (displayNameAttribute.NamedArguments.Length > 0)
{
return displayNameAttribute.NamedArguments[0].Value.Value?.ToString() ?? property.Name;
}

This chooses a bad display name when the attribute is used like this, for example:

        [Display(
            ResourceType = typeof(OptionsDisplayStrings),
            Description = nameof(OptionsDisplayStrings.DisplayAttributeDescription_CollectionRuleActionOptions_Name))]

The display name ends up as "Microsoft.Diagnostics.Monitoring.WebApi.OptionsDisplayString".

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions