FluentValidation.Blazor icon indicating copy to clipboard operation
FluentValidation.Blazor copied to clipboard

Upgraded to FluentValidation 10.x and .NET 6 Preview 3, getting the following error

Open zoinkydoink opened this issue 3 years ago • 5 comments

Error: System.MissingMethodException: Method not found: 'System.Collections.Generic.IList`1<FluentValidation.Results.ValidationFailure> FluentValidation.Results.ValidationResult.get_Errors()'.
   at Microsoft.AspNetCore.Components.Forms.FluentValidator.ValidateModel(EditContext editContext, ValidationMessageStore messages)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Microsoft.AspNetCore.Components.Forms.FluentValidator.ValidateModel(EditContext editContext, ValidationMessageStore messages)
   at Microsoft.AspNetCore.Components.Forms.FluentValidator.<>c__DisplayClass24_0.<AddValidation>b__0(Object sender, ValidationRequestedEventArgs eventArgs)
   at Microsoft.AspNetCore.Components.Forms.EditContext.Validate()
   at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

zoinkydoink avatar Apr 13 '21 16:04 zoinkydoink

we have also facing the same issue when upgrade the FluentValidation 9.0.0 preview 3 to 9.0.0 preview 4. and present in latet version 10 also

`@using FluentValidation <EditForm Model="Form">

<FluentValidator Validator="custVal"></FluentValidator>


<div class="form-group">
    <label for="email">Email</label>
    <InputText id="email" type="email" class="form-control" @bind-Value="Form.Email"></InputText>
    <ValidationMessage For="() => Form.Email"></ValidationMessage>
</div>
<div class="form-group">
    <button type="submit" class="btn btn-primary">
        <i class="fas fa-chevron-up"></i>
        Submit
    </button>
</div>

@code { FormModel Form = new FormModel(); FormModelValidator custVal = new FormModelValidator();

public class FormModel

{ public string Email { set; get; } }

public class FormModelValidator : AbstractValidator<FormModel> { public FormModelValidator() { RuleFor(Q => Q.Email).NotEmpty().EmailAddress().MaximumLength(255); } } } `

sureshkumar1115 avatar Apr 16 '21 08:04 sureshkumar1115

Hi @ryanelian, I just wanted to weigh in and provide some context on the above. This happens because FV's ValidationResult.Errors property was changed from an IList<ValidationFailure> to List<ValidationFailure> with the 10.0 release. The Accelist.FluentValidation.Blazor package doesn't currently contain an upper version limit for its FluentValidation dependency, so nuget will allow users to upgrade from FV 9 to 10 without warning them there's a compatibility issue.

The fix in this case is just to recompile against FV 10, but I'd also suggest patching the current release to add an upper version limit too.

I'd suggest the following:

  • Create a 4.0.1 patch release that provides an upper version constraint limiting the FluentValidation dependency to versions >= 9.5.4 && < 10.0 with <PackageReference Include="FluentValidation" Version="[9.5.4,10.0)" />
  • Additionally create a 5.0.0 major release that updates to FluentValidation 10 and includes a constraint of >= 10.0.4 && < 11.0 with with <PackageReference Include="FluentValidation" Version="[10.0.4,11.0)" />

Please feel free to ping me if you have questions about upgrading to 10.0

JeremySkinner avatar Apr 16 '21 16:04 JeremySkinner

@JeremySkinner I want to thank you for helping here as well, your dedication is extremely appreciated

zoinkydoink avatar Apr 16 '21 18:04 zoinkydoink

I made a fork to support FluentValidation 10.

I took the code from the version 5 branch and make the changes stated in this issue.

The idea is to make available an alternative (but compatible) nuget package until ryanelian can make an official release.

If you need FluentValidation 10 support check out https://github.com/pablopioli/FluentValidation.Blazor

pablopioli avatar Apr 27 '21 23:04 pablopioli

@pablopioli You are a legend!!!

carlblanchard avatar May 27 '21 09:05 carlblanchard