Skip to content

Conversation

@halter73
Copy link
Member

@halter73 halter73 commented Aug 6, 2021

This makes taking a struct as a "[FromBody]" parameter work rather than throw an exception like System.InvalidOperationException: The binary operator Equal is not defined for the types 'Contact' and 'System.Object'. Ex.

var app = WebApplication.Create(args);

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

app.Run();

record struct Contact(string pcfCode, string email);

Fixes #34842

@halter73 halter73 added feature-minimal-actions Controller-like actions for endpoint routing old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Aug 6, 2021
@ghost ghost added the area-runtime label Aug 6, 2021
@davidfowl
Copy link
Member

The PR description leaves much to be desired. I can't really tell where the fix is but I believe it works 😄

Expression.Assign(argument, convertedBodyValue),
Expression.IfThen(
Expression.Equal(argument, Expression.Constant(null)),
Expression.Equal(BodyValueExpr, Expression.Constant(null)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix. We don't cast from object to the struct type before checking bodyValue == null.

@halter73 halter73 merged commit 0a4f4ab into main Aug 9, 2021
@halter73 halter73 deleted the halter73/34842 branch August 9, 2021 19:39
@ghost ghost added this to the 6.0-rc1 milestone Aug 9, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimal APIs: Structs broken with parameter binding

4 participants