Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In ASP.NET 7, IEnumerable<> controller parameters do not bind from request body by default #45162

Closed
1 task done
0x03BB opened this issue Nov 18, 2022 · 3 comments · Fixed by #45173
Closed
1 task done
Assignees
Labels
bug This issue describes a behavior which is not expected - a bug. feature-model-binding old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone

Comments

@0x03BB
Copy link

0x03BB commented Nov 18, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In ASP.NET 7, a controller with an IEnumerable<> parameter is not bound from the body of the request by default. An empty array is seen by the controller. This worked in ASP.NET 6.

[HttpPost]
public IActionResult Post(IEnumerable<WeatherForecast> forecasts)
{
}

If the [FromBody] attribute is added to the parameter or List<> is used instead, the binding works. The linked GitHub project demonstrates this.

Expected Behavior

An IEnumerable<> parameter should be bound from the body by default, as it was in ASP.NET 6.

Steps To Reproduce

https://github.com/0x03BB/ParameterBindingIssue

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

Using Visual Studio 17.4.1
dotnet info.txt

@davidfowl
Copy link
Member

davidfowl commented Nov 18, 2022

@brunolins16 This might have to do with the change around inferring services implicitly.

@brunolins16
Copy link
Member

@brunolins16 This might have to do with the change around inferring services implicitly.

Ohh! Let me take a look.

@brunolins16 brunolins16 added investigate old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-model-binding labels Nov 18, 2022
@brunolins16 brunolins16 self-assigned this Nov 18, 2022
@brunolins16
Copy link
Member

Sadly ☹️, you are right, the call to IServiceProviderIsService.IsService return true for IEnumerable<> types.

https://github.com/dotnet/runtime/blob/d15a19fd4a9dd21fb768b6de4870a2d80acb3669/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs#L555

@brunolins16 brunolins16 added bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Nov 18, 2022
@rafikiassumani-msft rafikiassumani-msft added this to the 7.0.1 milestone Nov 23, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue describes a behavior which is not expected - a bug. feature-model-binding 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 a pull request may close this issue.

4 participants