Skip to content

Disallowing nullable with AsParameters attribute - #42812

Merged
brunolins16 merged 10 commits into
dotnet:mainfrom
brunolins16:brunolins16/issues/42210
Aug 3, 2022
Merged

brunolins16 merged 10 commits into
dotnet:mainfrom
brunolins16:brunolins16/issues/42210

Conversation

@brunolins16

@brunolins16 brunolins16 commented Jul 19, 2022 •

Copy link
Copy Markdown
Member

Fixes #42210

This PR change the AsParameters binding logic to not support nullable. That means the RequestDelegateFactory.Create will throw an InvalidOperationException when a nullable class/struct is defined with the AsParameters attribute, eg.:

app.MapGet("value-type", ([AsParameters] WeatherForecastStruct? args) => Results.Ok(args)).WithOpenApi();
app.MapGet("reference-type", ([AsParameters] WeatherForecast? args) => Results.Ok(args)).WithOpenApi();

internal record WeatherForecast(DateOnly? Date, int? TemperatureC, string? Summary);
internal record struct WeatherForecastStruct(DateOnly? Date, int? TemperatureC, string? Summary);

The binding will be allowed when reference type parameter is nullable-oblivious (compiled before C# 8, or in a disabled context), that are nullable.

@brunolins16 brunolins16 added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jul 19, 2022
@brunolins16
brunolins16 requested a review from a team July 19, 2022 17:38
@brunolins16 brunolins16 changed the title Allowing nullable struct with AsParameters attribute Disallowing nullable with AsParameters attribute Jul 28, 2022

@BrennanConroy BrennanConroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

".. is not supported, mark the parameter as non-nullable."
Maybe? Idk.

@brunolins16
brunolins16 enabled auto-merge (squash) August 2, 2022 16:37
@brunolins16

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@brunolins16
brunolins16 merged commit 2d5f11b into dotnet:main Aug 3, 2022
@ghost ghost added this to the 7.0-rc1 milestone Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Nullable struct not working with AsParameter

4 participants