From 7cda97d704374991c063aa7c01f1872e9336e63f Mon Sep 17 00:00:00 2001 From: Pent Ploompuu Date: Tue, 19 Nov 2019 23:42:09 +0200 Subject: [PATCH 1/2] Fix double expansion of AggregateException.Flatten message --- .../System.Private.CoreLib/src/System/AggregateException.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs b/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs index 46baebfddd6e7b..204a4f06ca9aad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs @@ -377,7 +377,7 @@ public AggregateException Flatten() while (exceptionsToFlatten.Count > nDequeueIndex) { // dequeue one from exceptionsToFlatten - IList currentInnerExceptions = exceptionsToFlatten[nDequeueIndex++].InnerExceptions; + ReadOnlyCollection currentInnerExceptions = exceptionsToFlatten[nDequeueIndex++].InnerExceptions; for (int i = 0; i < currentInnerExceptions.Count; i++) { @@ -401,8 +401,7 @@ public AggregateException Flatten() } } - - return new AggregateException(Message, flattenedExceptions); + return new AggregateException(GetType() == typeof(AggregateException) ? base.Message : Message, flattenedExceptions); } /// Gets a message that describes the exception. From 6bff61f8ab78e6b26f6a9d61cdba5adf4df53718 Mon Sep 17 00:00:00 2001 From: Pent Ploompuu Date: Sun, 22 Dec 2019 16:57:44 +0200 Subject: [PATCH 2/2] Update tests --- .../tests/AggregateExceptionTests.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Threading.Tasks/tests/AggregateExceptionTests.cs b/src/libraries/System.Threading.Tasks/tests/AggregateExceptionTests.cs index fdf4a5dac29a36..5692231026432e 100644 --- a/src/libraries/System.Threading.Tasks/tests/AggregateExceptionTests.cs +++ b/src/libraries/System.Threading.Tasks/tests/AggregateExceptionTests.cs @@ -2,10 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Xunit; -using System; using System.Collections.Generic; -using System.Diagnostics; +using Xunit; namespace System.Threading.Tasks.Tests { @@ -103,7 +101,9 @@ public static void Flatten() Exception exceptionB = new Exception("B"); Exception exceptionC = new Exception("C"); - AggregateException aggExceptionBase = new AggregateException(exceptionA, exceptionB, exceptionC); + AggregateException aggExceptionBase = new AggregateException("message", exceptionA, exceptionB, exceptionC); + + Assert.Equal("message (A) (B) (C)", aggExceptionBase.Message); // Verify flattening one with another. // > Flattening (no recursion)... @@ -114,15 +114,17 @@ public static void Flatten() }; Assert.Equal(expected1, flattened1.InnerExceptions); + Assert.Equal("message (A) (B) (C)", flattened1.Message); // Verify flattening one with another, accounting for recursion. - AggregateException aggExceptionRecurse = new AggregateException(aggExceptionBase, aggExceptionBase); + AggregateException aggExceptionRecurse = new AggregateException("message", aggExceptionBase, aggExceptionBase); AggregateException flattened2 = aggExceptionRecurse.Flatten(); Exception[] expected2 = new Exception[] { exceptionA, exceptionB, exceptionC, exceptionA, exceptionB, exceptionC, }; Assert.Equal(expected2, flattened2.InnerExceptions); + Assert.Equal("message (A) (B) (C) (A) (B) (C)", flattened2.Message); } } }