Created
August 23, 2012 18:54
-
-
Save thecodejunkie/3440281 to your computer and use it in GitHub Desktop.
.NET 4.5 verificationexception in FluentValidation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Due to implementation details in the current C# compiler, the code | |
public class AbstractValidator<T> | |
{ | |
Func<CascadeMode> cascadeMode = () => ValidatorOptions.CascadeMode; | |
} | |
will generate IL for the AbstractValidator<T> constructor that contains a branch that appears before the call to the base class constructor (the System.Object constructor in this case). In the workaround code | |
public class AbstractValidator<T> | |
{ | |
static Func<CascadeMode> s_cascadeMode = () => ValidatorOptions.CascadeMode; | |
Func<CascadeMode> cascadeMode = s_cascadeMode; | |
} | |
the C# compiler no longer emits the problematic branch into the constructor IL (again due to implementation details in the C# compiler). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment