Validation crashes for every rule (RuleFor(…).XXX())
See original GitHub issueHi, I was trying to use my app after migrating fluentvalidation and I experienced a crash at the very creation of the RuleFor() of my Validator. This crashes for all the Rules and seems to be a bug on CreateDelegate, even though I could not understand why this would crash.
My structure is the following:
- ViewModels (and validation) on a PCL Project, views made with Xamarin.Forms
- Specific project for each platform.
This seems not to crash on Android.
The exception is an ArgumentException
, with message "method argument length mismatch"
Here is the stacktrace for « .Email() »:
at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x0011b] in corlib/System/Delegate.cs:293
at System.Reflection.MethodInfo.CreateDelegate (System.Type delegateType, System.Object target) [0x00000] in src\FluentValidation\Internal\Compatibility.cs:55
at FluentValidation.Resources.StaticResourceAccessorBuilder.GetResourceAccessor (System.Type resourceType, System.String resourceName) [0x00064] in \src\FluentValidation\Resources\IResourceAccessorBuilder.cs:42
at FluentValidation.Resources.LocalizedStringSource..ctor (System.Type resourceType, System.String resourceName, IResourceAccessorBuilder resourceAccessorBuilder) [0x00006] in \src\FluentValidation\Resources\LocalizedStringSource.cs:40
at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression (System.Linq.Expressions.Expression1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy) [0x00043] in \src\FluentValidation\Resources\LocalizedStringSource.cs:68
at FluentValidation.Validators.PropertyValidator..ctor (System.Linq.Expressions.Expression1 errorMessageResourceSelector) [0x00011] in \src\FluentValidation\Validators\PropertyValidator.cs:54
at FluentValidation.Validators.EmailValidator..ctor () [0x00000] in \src\FluentValidation\Validators\EmailValidator.cs:33
at FluentValidation.DefaultValidatorExtensions.EmailAddress[LoginPageViewModel] (IRuleBuilder`2 ruleBuilder) [0x00000] in \src\FluentValidation\DefaultValidatorExtensions.cs:127 `
at --- MYCODE
And the stacktrace for « .Length(x, x) »:
at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x0011b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Delegate.cs:229
at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Delegate.cs:293
at System.Reflection.MethodInfo.CreateDelegate (System.Type delegateType, System.Object target) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MethodInfo.cs:174
at FluentValidation.Internal.Compatibility.CreateGetter (System.Reflection.PropertyInfo property) [0x00000] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Internal\\Compatibility.cs:55
at FluentValidation.Resources.StaticResourceAccessorBuilder.GetResourceAccessor (System.Type resourceType, System.String resourceName) [0x00064] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Resources\\IResourceAccessorBuilder.cs:42
at FluentValidation.Resources.LocalizedStringSource..ctor (System.Type resourceType, System.String resourceName, IResourceAccessorBuilder resourceAccessorBuilder) [0x00006] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Resources\\LocalizedStringSource.cs:40
at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression (System.Linq.Expressions.Expression1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy) [0x00043] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Resources\\LocalizedStringSource.cs:68
at FluentValidation.Validators.PropertyValidator..ctor (System.Linq.Expressions.Expression1 errorMessageResourceSelector) [0x00011] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Validators\\PropertyValidator.cs:54
at FluentValidation.Validators.LengthValidator..ctor (Int32 min, Int32 max, System.Linq.Expressions.Expression`1 errorMessageResourceSelector) [0x00000] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Validators\\LengthValidator.cs:32
at FluentValidation.Validators.LengthValidator..ctor (Int32 min, Int32 max) [0x00000] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\Validators\\LengthValidator.cs:29
at FluentValidation.DefaultValidatorExtensions.Length[LoginPageViewModel] (IRuleBuilder`2 ruleBuilder, Int32 min, Int32 max) [0x00000] in c:\\Projects\\FluentValidation\\src\\FluentValidation\\DefaultValidatorExtensions.cs:66
at ----MYCODE
Downgrading to 5.5.0.0 fixed the issue, I had not enough time to investigate on why it crashed.
All seems to get down to https://github.com/JeremySkinner/FluentValidation/blob/master/src/FluentValidation/Internal/Compatibility.cs Maybe this is a bug on mono ?
Hoping this helps you, do not hesitate to contact me for more infos on this.
Issue Analytics
- State:
- Created 8 years ago
- Comments:21 (7 by maintainers)
Top GitHub Comments
Please could you open a separate issue, and post some more details about your setup there? (Target platform, which do you’re referencing etc)
Hi i am using fluent validation for ui fileds in viewmodel how to update or highlight ui components when validation fails?