Exception netstandard 1.4 PCL
See original GitHub issueI’m trying to to validate a ViewModel in a netstandard 1.4 PCL. The code below crashes in the constructor of RegisterCmdValidator
with an ArgumentException
: “Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.”
This happens with 6.2.1 and the latest beta (6.4.0-beta9 at the time of writing).
Callstack:
at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags, StackCrawlMark& stackMark) at System.Reflection.RuntimeMethodInfo.CreateDelegate(Type delegateType) at FluentValidation.Resources.StaticResourceAccessorBuilder.GetResourceAccessor(Type resourceType, String resourceName) in C:\projects\FluentValidation\src\FluentValidation\Resources\IResourceAccessorBuilder.cs:line 44 at FluentValidation.Resources.LocalizedStringSource…ctor(Type resourceType, String resourceName, IResourceAccessorBuilder resourceAccessorBuilder) in C:\projects\FluentValidation\src\FluentValidation\Resources\LocalizedStringSource.cs:line 40 at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression(Expression
1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy) in C:\projects\FluentValidation\src\FluentValidation\Resources\LocalizedStringSource.cs:line 68 at FluentValidation.DefaultValidatorOptions.<>c__DisplayClass10_0
2.<WithLocalizedMessage>b__0(PropertyRule config) in C:\projects\FluentValidation\src\FluentValidation\DefaultValidatorOptions.cs:line 185 at FluentValidation.Internal.RuleBuilder2.FluentValidation.Internal.IConfigurable<FluentValidation.Internal.PropertyRule,FluentValidation.IRuleBuilderOptions<T,TProperty>>.Configure(Action
1 configurator) in C:\projects\FluentValidation\src\FluentValidation\Internal\RuleBuilder.cs:line 80 at FluentValidation.DefaultValidatorOptions.WithLocalizedMessage[T,TProperty](IRuleBuilderOptions2 rule, Expression
1 resourceSelector, IResourceAccessorBuilder resourceAccessorBuilder) in C:\projects\FluentValidation\src\FluentValidation\DefaultValidatorOptions.cs:line 184 at FluentValidation.DefaultValidatorOptions.WithLocalizedMessage[T,TProperty](IRuleBuilderOptions2 rule, Expression
1 resourceSelector) in C:\projects\FluentValidation\src\FluentValidation\DefaultValidatorOptions.cs:line 141 at ViewModels.RegistrationViewModel.RegisterCmdValidator…ctor(ICoreStrings coreStrings)
public class RegistrationViewModel
{
...
private readonly ICoreStrings coreStrings;
class RegisterCmdValidator : AbstractValidator<RegistrationViewModel>
{
public RegisterCmdValidator(ICoreStrings coreStrings)
{
RuleFor(vm => vm.Password).NotEmpty().WithLocalizedMessage(() => FluentValidation.Resources.Messages.notempty_error);
RuleFor(vm => vm.Password).Length(4, 15).WithLocalizedMessage(() => FluentValidation.Resources.Messages.length_error);
RuleFor(vm => vm.ConfirmPassword).NotEmpty().WithLocalizedMessage(() => FluentValidation.Resources.Messages.notempty_error);
// Crash
RuleFor(vm => vm.ConfirmPassword).Must((vm, password) => vm.Password == password).WithLocalizedMessage(() => coreStrings.ValidationPasswordConfirmMismatch);
// Works
RuleFor(vm => vm.ConfirmPassword).Must((vm, password) => vm.Password == password).WithMessage(coreStrings.ValidationPasswordConfirmMismatch);
}
}
readonly RegisterCmdValidator registerCmdValidator;
private string email;
public string Email
{
get { return email; }
set { this.RaiseAndSetIfChanged(ref email, value); }
}
private string password;
public string Password
{
get { return password; }
set { this.RaiseAndSetIfChanged(ref password, value); }
}
private string confirmPassword;
public string ConfirmPassword
{
get { return confirmPassword; }
set { this.RaiseAndSetIfChanged(ref confirmPassword, value); }
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
Yeah it’s not really obvious right now that the lambda has some hidden requirements. I think your proposed changes are spot on.
This has caused confusion a few times…I guess it comes from using a lambda for something unusual which isn’t expected.
I’m thinking of changing this behaviour for the next version:
What do you think?