Skip to content

Min API validation fails for Record types #61379

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

Closed
1 task done
mikekistler opened this issue Apr 8, 2025 · 1 comment
Closed
1 task done

Min API validation fails for Record types #61379

mikekistler opened this issue Apr 8, 2025 · 1 comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-validation Issues related to model validation in minimal and controller-based APIs

Comments

@mikekistler
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When the input of an API is a record type, the validation endpoint filter throws an exception.


System.InvalidOperationException: Property 'EqualityContract' not found on type 'Todo'.
   at Microsoft.AspNetCore.Http.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Validation.ValidatableParameterInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Validation.ValidationEndpointFilterFactory.<>c__DisplayClass0_0.<<Create>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.<ExecuteValueTaskOfObject>g__ExecuteAwaited|129_0(ValueTask`1 valueTask, HttpContext httpContext, JsonTypeInfo`1 jsonTypeInfo)
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass102_2.<<HandleRequestBodyAndCompileRequestDelegateForJson>b__2>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected Behavior

Validation should work correctly.

Steps To Reproduce

The "validation-record-types" project in this repo is a minimal repro of the problem:

https://github.com/mikekistler/dotnet10-issue-repros

The .http file contains a request that will trigger the error.

If you comment out the #define at the top of Program.cs, the project uses a class instead of a record and in this configuration the app works correctly.

Exceptions (if any)

No response

.NET Version

10.0.100-preview.3.25201.16

Anything else?

No response

@ghost ghost added the area-web-frameworks label Apr 8, 2025
@martincostello martincostello added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-validation Issues related to model validation in minimal and controller-based APIs and removed area-web-frameworks labels Apr 8, 2025
@captainsafia
Copy link
Member

This is fixed via #61402 in preview 4. Let me know if you run into any more issues with it!

sbomer added a commit to sbomer/dotnet-monitor that referenced this issue Apr 30, 2025
sbomer added a commit to sbomer/dotnet-monitor that referenced this issue May 9, 2025
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-validation Issues related to model validation in minimal and controller-based APIs
Projects
None yet
Development

No branches or pull requests

3 participants