Given the following class hierarchy:
class Base
{
protected virtual void Do(int value)
{
}
}
class Derived1 : Base
{
sealed protected override void Do(int value)
{
base.Do(value);
}
}
class Derived2 : Derived1
{
public Derived2()
{
Do(999);
}
}
... CA2214 code analysis warning is resolved by simply adding the keyword sealedin Derived1.Do(). So far so good.
Now let's do Do()generic:
class Base
{
protected virtual void Do<T>(T value)
{
}
}
class Derived1 : Base
{
sealed protected override void Do<T>(T value)
{
base.Do(value);
}
}
class Derived2 : Derived1
{
public Derived2()
{
Do(999);
}
}
Return CA2214. Why?
The warning description refers to the following call stack:
Derived2..ctor()
Base.Do<T>(T):Void
... although the breakpoint Derived1.Do()doesn’t hit just fine.
Note: this happens with both .NET 4.5 and 4.6
source
share