-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Missing IServiceProvider in ObjectGraphDataAnnotationsValidator #57573
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
Comments
Just ran into a similar issue with a custom validation attribute: In |
@S-Luiten I wrote a post about it here and here is the whole project. |
I just spent hours trying to work out why my ValidationAttribute descendant wasn't working only to find out this is the cause. @SteveSandersonMS @danroth27 is there any chance of this being fixed in a service release? Repro
|
@mrpmorris No, instead our focus is on shipping #46349 as part of .NET 10, which will be our stable and supported story for object graph validation in minimal APIs and Blazor. |
@danroth27 I reverse engineered the dll and all it needed was a few really minor changes. Is the source available somewhere, can I submit a PR, and would it be released if I did the work? I'd rather not have our own copy to maintain, and surely other people would benefit in the meantime before the V10 release? |
@mrpmorris We never shipped a stable release of the |
Is there an existing issue for this?
Describe the bug
In the
Validate
function of anIValidatableObject
model, no services can be loaded withGetRequiredService
ifValidate
was triggered byObjectGraphDataAnnotationsValidator
.The problem is that in
ObjectGraphDataAnnotationsValidator.ValidateObject
a newValidationContext
is created but theIServiceProvider
is missing.Source: https://github.com/dotnet/aspnetcore/tree/5da314644ae882ff22fb43101d0c3d89a35c40e9/src/Components/WebAssembly/Validation/src
This would fix the issue.
Class
Microsoft.AspNetCore.Components.Forms.ObjectGraphDataAnnotationsValidator
:Validate
=>System.ComponentModel.DataAnnotations.IValidatableObject.Validate
IValidatableObject
=>System.ComponentModel.DataAnnotations.IValidatableObject
GetRequiredService
=>Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T]
ObjectGraphDataAnnotationsValidator
=>Microsoft.AspNetCore.Components.Forms.ObjectGraphDataAnnotationsValidator
Expected Behavior
When calling
GetRequiredService[T]
in a model withIValidatableObject
the service should be returned.Steps To Reproduce
Update
button onHome
pageProject: https://github.com/TheBigNeo/ObjectGraphDataAnnotationsValidator_ServiceProvider
Error Line: https://github.com/TheBigNeo/ObjectGraphDataAnnotationsValidator_ServiceProvider/blob/332b7ac50201309c97a2586a6dd2ef627017e1da/ObjectGraphDataAnnotationsValidator_ServiceProvider/Components/Sample/Animal.cs#L27
Exceptions (if any)
.NET Version
8.0.400
Anything else?
The line to fix this bug comes from here:
https://stackoverflow.com/a/63855575/1847143
dotnet --info
The text was updated successfully, but these errors were encountered: