Skip to content

In ASP.NET 8, IReadOnlyCollection<> controller parameters do not bind from request body by default #52962

@IT-CASADO

Description

@IT-CASADO

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In ASP.NET 8, a controller with an IReadOnlyCollection<> 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. We are currently trying to migrate from .NET 6 to .NET 8.

If the [FromBody] attribute is added to the parameter or List<>/IEnumerable<> is used instead, the binding works.

This issue is similiar to this one #45162

Expected Behavior

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

Steps To Reproduce

Create a controller with this method:

[HttpPost]
public IActionResult Post(IReadOnlyCollection<SomeClass> data)
{
}

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions