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.

Nested .When operations causes exception

See original GitHub issue

Which 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:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Mar 22, 2021

I’ve pushed out a preview4 release that fixes this

0reactions
JeremySkinnercommented, Mar 22, 2021

Was an easy fix - will push out a new preview build in a couple of hours.

Read more comments on GitHub >

github_iconTop 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 >

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