private static Exception TryUnwrapAggregateException(AggregateException aggregateException) { if (aggregateException == null) return null; if (aggregateException.InnerExceptions.Count == 1) return aggregateException.InnerExceptions[0]; return aggregateException; } }