static Exception Flatten(Exception tr) { if (!(tr is AggregateException)) return tr; var err = ((AggregateException)tr).Flatten().InnerException; return err; }