Nested .When operations causes exception
See original GitHub issueWhich version of FluentValidation are you using? 10.0.0-preview3
Describe the issue that you’re having The following code causes an exception when the validator is instantiated
public class SomeType
{
public bool Value1 { get; set; }
public bool Value2 { get; set; }
}
public class SomeTypeValidator : AbstractValidator<SomeType>
{
public SomeTypeValidator()
{
this.When(
o => o.Value1,
() =>
{
// do stuff
})
.Otherwise(
() =>
{
this.When(
o => o.Value2,
() =>
{
// do stuff
});
});
}
}
System.ArgumentException
Delegates must be of the same type.
at System.MulticastDelegate.CombineImpl(Delegate follow)
at FluentValidation.Internal.TrackingCollection`1.add_ItemAdded(Action`1 value)
at FluentValidation.Internal.TrackingCollection`1.OnItemAdded(Action`1 onItemAdded) in C:\Projects\FluentValidation\src\FluentValidation\Internal\TrackingCollection.cs:line 48
at FluentValidation.Internal.ConditionBuilder`1.When(Func`3 predicate, Action action) in C:\Projects\FluentValidation\src\FluentValidation\Internal\ConditionBuilder.cs:line 40
at FluentValidation.AbstractValidator`1.When(Func`3 predicate, Action action) in C:\Projects\FluentValidation\src\FluentValidation\AbstractValidator.cs:line 302
at FluentValidation.AbstractValidator`1.When(Func`2 predicate, Action action) in C:\Projects\FluentValidation\src\FluentValidation\AbstractValidator.cs:line 292
at Nordic.Application.Sales.Tests.StructuralRules.ElementToggling.Common.TestObjValidator.<.ctor>b__0_2() in D:\source\roadmap\src\Core\Nordic.Application.Sales.Tests\StructuralRules\ElementToggling\Common.cs:line 63
at FluentValidation.Internal.ConditionOtherwiseBuilder`1.Otherwise(Action action) in C:\Projects\FluentValidation\src\FluentValidation\Internal\ConditionBuilder.cs:line 161
It appears that it’s trying to combine two delegates where one is Action<IValidationRule<T>>
and the other is Action<IValidationRuleInternal<T>>
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Nested causes in nested exceptions in python [duplicate]
Is there a way to provide information about the cause of an inner exception when passing it up the chain (like it's possible...
Read more >Nested Exceptions
A nested exception is an exception that occurs while another exception is being handled. When this happens: Processing of the first exception is...
Read more >Nested Exceptions in Java: Definition & Example
A nested exception, or chain, is when the exception is thrown from a catch block and includes another exception (usually the one that...
Read more >Exception handling scope when dealing with nested ...
If for some reason you need to handle the two exception types differently, then Option 4 is better. Note that "hiding where the...
Read more >Nested Exception - C2 wiki
The general idea is that exceptions should include references to the exception that caused them. When a layer catches an exception and throws...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve pushed out a preview4 release that fixes this
Was an easy fix - will push out a new preview build in a couple of hours.