Skip to content

Inconsistent model binding between IFormFileCollection, IReadOnlyList<IFormFile> and other collection types in Minimal APIs #54999

@KennethHoff

Description

@KennethHoff

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Minimal API form binding works differently based on which interface types you choose to use:

  • IFormFileCollection binds every file regardless of their name.
    • Prior to noticing this issue I always used this type if I wanted to get a collection of files, as it seemed like the obvious one based on the name.
  • IReadOnlyList<IFormFile> binds all the ones with the corresponding names.
    • This is what I thought IFormFileCollection did.
  • All the other collection interfaces (IEnumerable<IFormFile>, IReadOnlyCollection<IFormFile>, IList<IFormFile>, and ICollection<IFormFile>) and their implementations (List<IFormFile>, IFormFile[], Collection<IFormFile>, and ReadOnlyCollection<IFormFile>) do not work at all.
    • This is fine for my use-case, just wanted to mention it for completeness sake.

Expected Behavior

IFormFileCollection respects the name of the property.

Steps To Reproduce

https://github.com/KennethHoff/Repros/tree/master/AspNetCoreMinimalApiInconsistentFormFileCollectionModelBinding

Exceptions (if any)

No response

.NET Version

8.0.202

Anything else?

I realize this is a (huge?) breaking change and this issue will therefore probably never be dealt with, but if nothing else I hope I'll save another developer some time in the future.

The only "documentation" I found of this behaviour is this comment thread on a Pull Request from last year.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsThis issue tracks updating documentationarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions