From 15db7abcb1aaec8f29f0029bc73632494dc281b3 Mon Sep 17 00:00:00 2001 From: stephentoub Date: Wed, 13 Jan 2016 13:37:47 -0500 Subject: Override AggregateException.Message to include more detail ToString() includes details on inner exceptions, but Message does not, with the default message just saying "One or more errors occurred." This commit overrides Message to append the messages of the inner exceptions as well. --- src/mscorlib/src/System/AggregateException.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/mscorlib/src/System/AggregateException.cs b/src/mscorlib/src/System/AggregateException.cs index 025d21cb6b..0c58cb4ed5 100644 --- a/src/mscorlib/src/System/AggregateException.cs +++ b/src/mscorlib/src/System/AggregateException.cs @@ -17,6 +17,7 @@ using System.Globalization; using System.Runtime.ExceptionServices; using System.Runtime.Serialization; using System.Security; +using System.Text; using System.Threading; namespace System @@ -431,6 +432,30 @@ namespace System return new AggregateException(Message, flattenedExceptions); } + /// Gets a message that describes the exception. + public override string Message + { + get + { + if (m_innerExceptions.Count == 0) + { + return base.Message; + } + + StringBuilder sb = StringBuilderCache.Acquire(); + sb.Append(base.Message); + sb.Append(' '); + for (int i = 0; i < m_innerExceptions.Count; i++) + { + sb.Append('('); + sb.Append(m_innerExceptions[i].Message); + sb.Append(") "); + } + sb.Length -= 1; + return StringBuilderCache.GetStringAndRelease(sb); + } + } + /// /// Creates and returns a string representation of the current . /// -- cgit v1.2.3