Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created August 23, 2012 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodejunkie/3440281 to your computer and use it in GitHub Desktop.
Save thecodejunkie/3440281 to your computer and use it in GitHub Desktop.
.NET 4.5 verificationexception in FluentValidation
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