Print Inner Exceptions in ReflectionTypeLoadException ToString (#15688)
authorWilliam Godbe <wigodbe@microsoft.com>
Wed, 3 Jan 2018 18:42:37 +0000 (10:42 -0800)
committerGitHub <noreply@github.com>
Wed, 3 Jan 2018 18:42:37 +0000 (10:42 -0800)
* Print Inner Exceptions in ReflectionTypeLoadException ToString

* Simplify formatting

* Remove tab

* Fix newlines

* Use AppendLine

* Use foreach

* Remove ToString

* Update string & message

* Modify Message

* Remove parens

src/mscorlib/Resources/Strings.resx
src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs

index 66eb172..929cbdd 100644 (file)
     <value>The specified arrays must have the same number of dimensions.</value>
   </data>
   <data name="ReflectionTypeLoad_LoadFailed" xml:space="preserve">
-    <value>Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.</value>
+    <value>Unable to load one or more of the requested types.</value>
   </data>
   <data name="Remoting_AppDomainUnloaded_ThreadUnwound" xml:space="preserve">
     <value>The application domain in which the thread was running has been unloaded.</value>
index a411387..a1ee323 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Runtime.Serialization;
+using System.Text;
 
 namespace System.Reflection
 {
@@ -39,6 +40,38 @@ namespace System.Reflection
             info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[]));
         }
 
+        public override string Message
+        {
+            get
+            {
+                if (LoaderExceptions.Length == 0)
+                {
+                    return base.Message;
+                }
+
+                StringBuilder text = new StringBuilder();
+                text.AppendLine(base.Message);
+                foreach (Exception e in LoaderExceptions)
+                {
+                    text.AppendLine(e.Message);
+                }
+                return text.ToString();
+            }
+        }
+
+        public override string ToString()
+        {
+            StringBuilder text = new StringBuilder();
+            text.AppendLine(SR.ReflectionTypeLoad_LoadFailed);
+
+            foreach (Exception e in LoaderExceptions)
+            {
+                text.AppendLine(e.ToString());
+            }
+
+            return text.ToString();
+        }
+
         public Type[] Types { get; }
 
         public Exception[] LoaderExceptions { get; }