question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation crashes for every rule (RuleFor(…).XXX())

See original GitHub issue

Hi, 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:closed
  • Created 8 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Dec 23, 2015

Please could you open a separate issue, and post some more details about your setup there? (Target platform, which do you’re referencing etc)

0reactions
MridulMalviyacommented, Jan 8, 2018

Hi i am using fluent validation for ui fileds in viewmodel how to update or highlight ui components when validation fails?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation crashes for every rule (RuleFor(…).XXX()) #70
Hi, I was trying to use my app after migrating fluentvalidation and I experienced a crash at the very creation of the RuleFor()...
Read more >
Validate a collection with FluentValidation returning one ...
I would expect one error for each rule to be returned, even though Rule #2 has failed twice. How can I accomplish this?...
Read more >
Validation rule crashes when fields required are populated ...
When I Clone a ticket that has been closed before, and has all needed fields populated, I create a new cloned record of...
Read more >
Creating your first validator
The validation rules themselves should be defined in the validator class's constructor. To specify a validation rule for a particular property, call the...
Read more >
Import Attribute Rules crashes... (PRO-2.9.5)
Hi all. After having created two simple Feature on Feature Validation rules, I have exported them (CSV). Unfortunatly, trying to load them ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found