-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
CompareAttribute.IsValid results in null ref #42490
Comments
Well I find problem.. Its CompareProperty attribute. |
If anyone else struggles with same issue. I did workaround. However I dont know whats happening inside IsValid?
|
Thanks for contacting us. |
@mkArtakMSFT well issue is in IsValid method of class ComparePropertyAttribute inside nuget package Microsoft.AspNetCore.Components.DataAnnotations.Validation which should be in this repo right? |
@glararan can you please provide a repro project? |
@mkArtakMSFT steps:
|
Tagging subscribers to this area: @ajcvickers |
Moved to the runtime repo to provide a better error message for this case. That said, you are going to unable to call IsValid on individual attributes and get the right result. Have a look at how Blazor implements it's validation: https://github.com/dotnet/aspnetcore/blob/f52077f599f0d3b4545d8f87a0c3d15217b33069/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs#L26 |
I got the same null issue with CompareAttribute.IsValid(object value), so I use GetValidationResult(object value, ValidationContext validationContext) instead. |
The fix is done to avoid NRE when CompareAttribute's implementation of IsValid(object? value, ValidationContext validationContext) is called with validationContext == null. Fix dotnet#42490
Stack trace:
Describe the bug
I have multiple models however each model which contains Password/ConfirmPassword cause crash after setting ConfirmPassword. (EDIT: I found out its caused by CompareProperty attribute)
To Reproduce
I implemented my own ValidationContext class which validates on field changed (EditContext) all attributes per changing field.
Implementation of ValidationContext for OnFieldChanged looks like this:
Crashing on this place. Only if I change field ConfirmPassword!
Debugger says e.FieldIdentifier.FieldName is "ConfirmPassword"
Model definition
Razor
Exceptions (if any)
Further technical details
Any idea how to get more debug info?
The text was updated successfully, but these errors were encountered: