AspNetCoreOData
AspNetCoreOData copied to clipboard
AmbiguousMatchException using .AddValidation()
Assemblies affected ASP.NET Core OData 9.4.1
Describe the bug
When adding AddValidation() that was introduced with .NET 10 to a project that uses AddOData() you get an AmbiguousMatchException when calling an OData endpoint.
Reproduce steps
For a minimal API endpoint containing parameter ODataQueryOptions<ApplicationUser> options. This can be remediated by adding DisableValidation() to the MapGet definition.
Additional context
System.Reflection.AmbiguousMatchException: Ambiguous match found for 'Microsoft.AspNetCore.OData.Query.ODataQueryOptions`1[Project.Models.ApplicationUser] Microsoft.AspNetCore.OData.Query.ETag`1[Project.Models.ApplicationUser] IfMatch'.
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetProperty(String name, BindingFlags bindingAttr)
at Microsoft.Extensions.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateMembersAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableParameterInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.Validation.ValidationEndpointFilterFactory.<>c__DisplayClass1_0.<<Create>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<ExecuteValueTaskOfObject>g__ExecuteAwaited|130_0(ValueTask`1 valueTask, HttpContext httpContext, JsonTypeInfo`1 jsonTypeInfo)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass101_0.<<HandleRequestBodyAndCompileRequestDelegate>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)