Open glararan opened 4 years ago
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?
foreach(ValidationAttribute attribute in attributes)
{
if (attribute is ComparePropertyAttribute comparePropertyAttribute)
{
PropertyInfo compareProperty = Model.GetType().GetProperty(comparePropertyAttribute.OtherProperty);
if (compareProperty != null && (string)property.GetValue(Model) != (string)compareProperty.GetValue(Model))
errors.Add(comparePropertyAttribute.ErrorMessage);
}
else if (!attribute.IsValid(property.GetValue(Model)))
errors.Add(attribute.ErrorMessage);
}
Thanks for contacting us. It's not clear where in Blazor the error is here. The exception you're referring to indicates an error from your own code. If you believe there is an issue in the framework, please file a new issue with a minimalistic code to help repro the error.
@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 successfully reproduced at https://github.com/glararan/22709/tree/master/22709
steps:
launch project navigate into 22709 type something to "Password" type something to "Confirm Password" unfocus Confirm Password exception is thrown
Tagging subscribers to this area: @ajcvickers See info in area-owners.md if you want to be subscribed.
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.
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?