Skip to content

Commit b6ae4c0

Browse files
committed
Flatten AggregateException with single inner exception
1 parent f5d3372 commit b6ae4c0

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Orm/Xtensive.Orm/Orm/Domain.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public sealed class Domain : IDisposable, IAsyncDisposable, IHasExtensions, ISes
5858
public event EventHandler Disposing;
5959

6060
/// <summary>
61-
/// Gets the <see cref="Domain"/> of the current <see cref="Session"/>.
61+
/// Gets the <see cref="Domain"/> of the current <see cref="Session"/>.
6262
/// </summary>
6363
/// <seealso cref="Session.Current"/>
6464
/// <seealso cref="Demand"/>
@@ -70,7 +70,7 @@ public static Domain Current {
7070
}
7171

7272
/// <summary>
73-
/// Gets the <see cref="Domain"/> of the current <see cref="Session"/>, or throws <see cref="InvalidOperationException"/>,
73+
/// Gets the <see cref="Domain"/> of the current <see cref="Session"/>, or throws <see cref="InvalidOperationException"/>,
7474
/// if active <see cref="Session"/> is not found.
7575
/// </summary>
7676
/// <returns>Current domain.</returns>
@@ -80,7 +80,7 @@ public static Domain Demand()
8080
{
8181
return Session.Demand().Domain;
8282
}
83-
83+
8484
/// <summary>
8585
/// Gets the domain configuration.
8686
/// </summary>
@@ -356,8 +356,11 @@ internal async Task<Session> OpenSessionInternalAsync(SessionConfiguration confi
356356
session.AttachToScope(sessionScope);
357357
}
358358
}
359-
else if (t.Exception != null) {
360-
exceptionDispatchInfo = ExceptionDispatchInfo.Capture(t.Exception);
359+
else if (t.Exception is Exception ex) {
360+
if (ex is System.AggregateException aggregateException && aggregateException.InnerExceptions.Count == 1) {
361+
ex = aggregateException.InnerExceptions[0];
362+
}
363+
exceptionDispatchInfo = ExceptionDispatchInfo.Capture(ex);
361364
}
362365
}, TaskContinuationOptions.ExecuteSynchronously)
363366
.ConfigureAwait(false);
@@ -380,7 +383,7 @@ internal async Task<Session> OpenSessionInternalAsync(SessionConfiguration confi
380383

381384
/// <inheritdoc/>
382385
public IExtensionCollection Extensions { get; private set; }
383-
386+
384387
#endregion
385388

386389
/// <summary>

0 commit comments

Comments
 (0)