-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Transform doen't work for RuleForEach #1450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting, that looks like a bug. Ideally when used with RuleForEach it should work against the collection elements (while it would work against the whole collection when used with RuleFor). I'll look at this as part of the 9.1 release. |
Thank you! |
For my case this fix works perfect, thanks a lot. |
I’ll close it once it’s merged - thanks. |
9.1 is now available on nuget with this change. |
Version of FluentValidation: 9.0.0
.NET Framework 4.7
Description
Given the following code (which compiles fine) I'd expect
Transform
will be applied for each collection member.But in runtime call
new Validator().Validate(new ModelWithCollection())
thows an exceptionSystem.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[System.Int32]' to type 'System.Int32'.'
This occurs in
FluentValidation.Internal.Extensions.CoerceToNonGeneric<T, TProperty>
.Obviously,
Transform
behaves the same way for simple property and for collection rules, so in this case it gets whole collection as input, but inner function expects collection element.I'd expect
Transfom
either fail to compile in this case, or clearly state it will work with collection, or work with each separate element.The text was updated successfully, but these errors were encountered: