From 3210b9ea76f2612b1ef014a2e570b72f994bc509 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Wed, 3 Jan 2018 20:35:55 -0800 Subject: [PATCH] Check for null in ReflectionTypeLoadException Message/ToString (#15711) --- .../System/Reflection/ReflectionTypeLoadException.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs b/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs index df44bac..d78c068 100644 --- a/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs +++ b/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs @@ -44,7 +44,7 @@ namespace System.Reflection { get { - if (LoaderExceptions.Length == 0) + if (LoaderExceptions == null || LoaderExceptions.Length == 0) { return base.Message; } @@ -53,7 +53,10 @@ namespace System.Reflection text.AppendLine(base.Message); foreach (Exception e in LoaderExceptions) { - text.AppendLine(e.Message); + if (e != null) + { + text.AppendLine(e.Message); + } } return text.ToString(); } @@ -63,10 +66,15 @@ namespace System.Reflection { StringBuilder text = new StringBuilder(); text.AppendLine(base.ToString()); - - foreach (Exception e in LoaderExceptions) + if (LoaderExceptions != null) { - text.AppendLine(e.ToString()); + foreach (Exception e in LoaderExceptions) + { + if (e != null) + { + text.AppendLine(e.ToString()); + } + } } return text.ToString(); -- 2.7.4