I get complete set of nested exceptions when I use ToString()
method on AggregateException
directly:
public void GreenTest()
{
var ex = new AggregateException(new Exception("ex1"), new Exception("ex2"));
ex.ToString()
.Should()
.Contain("ex1")
.And
.Contain("ex2");
}
The problem is I get only the first exception when the AggregateException
is wrapped in another exception:
public void RedTest()
{
var ex = new Exception("wrapper", new AggregateException(new Exception("ex1"), new Exception("ex2")));
ex.ToString()
.Should()
.Contain("wrapper")
.And
.Contain("ex1")
.And
.Contain("ex2");
}
ex2
isn't present in the resulting string. Is this a bug or some well-known feature of AggregateException
class?