Skip to content

InvalidOperationException when using string[] parameters with FromForm attribute #62326

@marcominerva

Description

@marcominerva
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a Minimal API with the following endpoint:

app.MapPost("/api/documents", ([FromForm] string[] values) =>
{
    return TypedResults.Ok();
});

When I run the project, I get the following exception:

An unhandled exception has occurred while executing the request.
      System.InvalidOperationException: TryParse method found on string with incorrect format. Must be a static method with format
      bool TryParse(string, IFormatProvider, out string)
      bool TryParse(string, out string)
      but found
      static Boolean TryParse(System.ReadOnlySpan`1[System.Char], System.IFormatProvider, System.String ByRef)

If I try with other types, like int[], it works correctly.

Exceptions (if any)

An unhandled exception has occurred while executing the request.
      System.InvalidOperationException: TryParse method found on string with incorrect format. Must be a static method with format
      bool TryParse(string, IFormatProvider, out string)
      bool TryParse(string, out string)
      but found
      static Boolean TryParse(System.ReadOnlySpan`1[System.Char], System.IFormatProvider, System.String ByRef)
         at Microsoft.AspNetCore.Http.ParameterBindingMethodCache.<FindTryParseMethod>g__Finder|18_0(Type type)
         at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
         at Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasTryParseMethod(Type type)
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgument(ParameterInfo parameter, RequestDelegateFactoryContext factoryContext, Boolean& hasTryParse, Boolean& hasBindAsync, Boolean& isAsParameters)
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArguments(ParameterInfo[] parameters, RequestDelegateFactoryContext factoryContext)
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgumentsAndInferMetadata(MethodInfo methodInfo, RequestDelegateFactoryContext factoryContext)
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.InferMetadata(MethodInfo methodInfo, RequestDelegateFactoryOptions options)
         at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.CreateRouteEndpointBuilder(RouteEntry entry, RoutePattern groupPrefix, IReadOnlyList`1 groupConventions, IReadOnlyList`1 groupFinallyConventions)
         at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.get_Endpoints()
         at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.CreateEndpointsUnsynchronized()
         at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.EnsureEndpointsInitialized()
         at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.get_Endpoints()
         at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize()
         at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
         at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func`1 matcherBuilderFactory)
         at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|10_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

.NET Version

9.0.301

Activity

added
needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
on Jun 12, 2025
changed the title [-]InvalidOperationException when using string[] parameters with [FromForm] attribute[/-] [+]InvalidOperationException when using string[] parameters with FromForm attribute[/+] on Jun 12, 2025
added
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
and removed
needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
on Jun 12, 2025
captainsafia

captainsafia commented on Aug 2, 2025

@captainsafia
Member

I think this bug is in RDF and is a combination of the interactions between POST metods + [FromForm] attributes + array-based types. Similar issues don't occur when PublishAoT=true and the source generator is at play.

Moving to the backlog for now given prioritization although PRs are welcome. I suspect the bug is related to the logic in thttps://github.com/dotnet/aspnetcore/blob/5d0e0d0dc65d9018faa1d9ce7892e7f4b6238b9d/src/Http/Http.Extensions/src/RequestDelegateFactory.cs#L763.

added this to the Backlog milestone on Aug 2, 2025
dotnet-policy-service

dotnet-policy-service commented on Aug 2, 2025

@dotnet-policy-service
Contributor

Looks like this issue has been identified as a candidate for community contribution. If you're considering sending a PR for this issue, look for the Summary Comment link in the issue description. That comment has been left by an engineer on our team to help you get started with handling this issue. You can learn more about our Help Wanted process here

linked a pull request that will close this issue on Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdfhelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @martincostello@captainsafia@marcominerva

      Issue actions

        InvalidOperationException when using string[] parameters with FromForm attribute · Issue #62326 · dotnet/aspnetcore