Skip to content

Cannot bind StringValues for HTTP request header with Minimal APIs #54536

Open
@GihanSoft

Description

@GihanSoft

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

using FromHeader attribute on minimal API parameter with type StringValues type produce error on build and analyze

Program.cs(7,18,7,70): error ASP0020: Parameter 'ifMatch' of type StringValues should define a bool TryParse(string, IFormatProvider, out StringValues) method, or implement IParsable<StringValues> (https://aka.ms/aspnet/analyzers)

Expected Behavior

No response

Steps To Reproduce

build this code:

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", ([FromHeader(Name = "If-Match")] StringValues ifMatch) => ifMatch);

app.Run();

Exceptions (if any)

No response

.NET Version

8.0.202

Anything else?

there is an issue (#40752) that address same bug in previous versions. It seems it's returned again

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzerIndicates an issue which is related to analyzer experiencearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions