I was testing the effects of calling a virtual member in a constructor, and discovered that when calling that member the resulting exception was wrapped within a TargetInvocationException
.
According to the docs this is:
The exception that is thrown by methods invoked through reflection
However I'm unaware of any invokations via reflection. So does this mean virtual members are always called via reflection? If not why is it so in this case?
The code:
class ClassA
{
public ClassA()
{
SplitTheWords();
}
public virtual void SplitTheWords()
{
//I've been overidden
}
}
class ClassB : ClassA
{
private readonly String _output;
public ClassB()
{
_output = "Constructor has occured";
}
public override void SplitTheWords()
{
String[] something = _output.Split(new[]{' '}); //TargetInvocationException!
}
}