My project compiles in VS 2013 but does not compile in VS 2015. Below code reproduces the compile problem. The Validator classes are actually in a 3rd party assembly so I can not change the implementation. The require class is a local class but I don't want to change the implementation because I will have to change lots of validation logic. Below is the code that does not compile in VS 2015.
public abstract class Validator<T> : Validator
{
public override void DoValidate(object objectToValidate)
{
}
protected abstract void DoValidate(T objectToValidate);
}
public abstract class Validator
{
public abstract void DoValidate(object objectToValidate);
}
public abstract class ValidatorBase<T> : Validator<T>
{
protected override void DoValidate(T objectToValidate)
{
}
}
public class Required : ValidatorBase<object>
{
}
Is there a workaround for this compilation issue? Any help would be appreciated.
The Error:
Severity Code Description Project File Line Error CS0534 'Required' does not implement inherited abstract member 'Validator<object>.DoValidate(object)' Program.cs 38
I tried to find a reason of this behavior, I failed.
I did find a workaround though. The code you posted compiles when ValidatorBase<T>
is not abstract. I know you can't change it, but you can add another non-abstract class to the inheritance chain:
public class Workaround<T> : ValidatorBase<T> { }
public class Required : Workaround<object>
{
}
It looks like Roslyn doesn't resolve the overridden methods in abstract classes until a non-abstract derived class is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With