Skip to content

Minimal APIs: Structs broken with parameter binding #34842

Closed
@davidfowl

Description

@davidfowl

Describe the bug

Structs are broken with parameter binding

To Reproduce

var app = WebApplication.Create(args);

app.MapPost("/api/contact", (Contact dto) => $"{dto.pcfCode} {dto.email}");

app.Run();

record struct Contact(string pcfCode, string email);

Exceptions (if any)

Unhandled exception. System.InvalidOperationException: The binary operator Equal is not defined for the types 'Contact' and 'System.Object'.
   at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull) in System.Linq.Expressions.dll:token 0x60001d3+0xdb
   at System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method) in System.Linq.Expressions.dll:token 0x60001ce+0x1f
   at System.Linq.Expressions.Expression.Equal(Expression left, Expression right) in System.Linq.Expressions.dll:token 0x60001cd+0x0
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.BindParameterFromBody(ParameterInfo parameter, Boolean allowEmpty, FactoryContext factoryContext) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x600006c+0x7e 
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgument(ParameterInfo parameter, FactoryContext factoryContext) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x6000061+0x24d
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArguments(ParameterInfo[] parameters, FactoryContext factoryContext) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x6000060+0x1a
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateTargetableRequestDelegate(MethodInfo methodInfo,C:\Users\david\source\repos\WebApplication511\WebApplication1> dotnet run
Building...
Unhandled exception. System.InvalidOperationException: The binary operator Equal is not defined for the types 'Contact' and 'System.Object'.
   at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull) in System.Linq.Expressions.dll:token 0x60001d3+0xdb
   at System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method) in System.Linq.Expressions.dll:token 0x60001ce+0x1f
   at System.Linq.Expressions.Expression.Equal(Expression left, Expression right) in System.Linq.Expressions.dll:token 0x60001cd+0x0
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.BindParameterFromBody(ParameterInfo parameter, Boolean allowEmpty, FactoryContext factoryContext) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x600006c+0x7e 
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgument(ParameterInfo parameter, FactoryContext factoryContext) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x6000061+0x24d
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArguments(ParameterInfo[] parameters, FactoryContext factoryContext) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x6000060+0x1a
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateTargetableRequestDelegate(MethodInfo methodInfo, RequestDelegateFactoryOptions options, Expression targetExpression) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x600005f+0x3b
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.Create(Delegate action, RequestDelegateFactoryOptions 
options) in Microsoft.AspNetCore.Http.Extensions.dll:token 0x600005d+0x4e
   at Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.Map(IEndpointRouteBuilder endpoints, RoutePattern pattern, Delegate action) in Microsoft.AspNetCore.Routing.dll:token 0x600004e+0x90       
   at Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapMethods(IEndpointRouteBuilder endpoints, String pattern, IEnumerable`1 httpMethods, Delegate action) in Microsoft.AspNetCore.Routing.dll:token 0x600004c+0x0
   at Microsoft.AspNetCore.Builder.MinimalActionEndpointRouteBuilderExtensions.MapPost(IEndpointRouteBuilder 
endpoints, String pattern, Delegate action) in Microsoft.AspNetCore.Routing.dll:token 0x6000049+0x0
   at <Program>$.<Main>$(String[] args) in C:\Users\david\source\repos\WebApplication511\WebApplication1\Program.cs:line 14

Metadata

Metadata

Assignees

Labels

Priority:0Work that we can't release withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.feature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions