Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4d26be5

Browse files
authored
Print Inner Exceptions in ReflectionTypeLoadException ToString (#15688)
* 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
1 parent c1b2aca commit 4d26be5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/mscorlib/Resources/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3284,7 +3284,7 @@
32843284
<value>The specified arrays must have the same number of dimensions.</value>
32853285
</data>
32863286
<data name="ReflectionTypeLoad_LoadFailed" xml:space="preserve">
3287-
<value>Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.</value>
3287+
<value>Unable to load one or more of the requested types.</value>
32883288
</data>
32893289
<data name="Remoting_AppDomainUnloaded_ThreadUnwound" xml:space="preserve">
32903290
<value>The application domain in which the thread was running has been unloaded.</value>

src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Runtime.Serialization;
6+
using System.Text;
67

78
namespace System.Reflection
89
{
@@ -39,6 +40,38 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
3940
info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[]));
4041
}
4142

43+
public override string Message
44+
{
45+
get
46+
{
47+
if (LoaderExceptions.Length == 0)
48+
{
49+
return base.Message;
50+
}
51+
52+
StringBuilder text = new StringBuilder();
53+
text.AppendLine(base.Message);
54+
foreach (Exception e in LoaderExceptions)
55+
{
56+
text.AppendLine(e.Message);
57+
}
58+
return text.ToString();
59+
}
60+
}
61+
62+
public override string ToString()
63+
{
64+
StringBuilder text = new StringBuilder();
65+
text.AppendLine(SR.ReflectionTypeLoad_LoadFailed);
66+
67+
foreach (Exception e in LoaderExceptions)
68+
{
69+
text.AppendLine(e.ToString());
70+
}
71+
72+
return text.ToString();
73+
}
74+
4275
public Type[] Types { get; }
4376

4477
public Exception[] LoaderExceptions { get; }

0 commit comments

Comments
 (0)