Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,34 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;

namespace System.Reflection
{
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class ReflectionTypeLoadException : SystemException, ISerializable
{
public ReflectionTypeLoadException(Type[]? classes, Exception?[]? exceptions)
: base(null)
public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions) :
this(classes, exceptions, null)
{
Types = classes;
LoaderExceptions = exceptions;
HResult = HResults.COR_E_REFLECTIONTYPELOAD;
}

public ReflectionTypeLoadException(Type[]? classes, Exception?[]? exceptions, string? message)
public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions, string? message)
: base(message)
{
Types = classes;
LoaderExceptions = exceptions;
Types = classes ?? Type.EmptyTypes;
LoaderExceptions = exceptions ?? Array.Empty<Exception>();
HResult = HResults.COR_E_REFLECTIONTYPELOAD;
}

private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
LoaderExceptions = (Exception[]?)(info.GetValue("Exceptions", typeof(Exception[])));
Types = Type.EmptyTypes;
LoaderExceptions = (Exception?[]?)info.GetValue("Exceptions", typeof(Exception[])) ?? Array.Empty<Exception?>();
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
Expand All @@ -40,9 +39,9 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[]));
}

public Type[]? Types { get; }
public Type?[] Types { get; }

public Exception?[]? LoaderExceptions { get; }
public Exception?[] LoaderExceptions { get; }

public override string Message => CreateString(isMessage: true);

Expand All @@ -52,8 +51,8 @@ private string CreateString(bool isMessage)
{
string baseValue = isMessage ? base.Message : base.ToString();

Exception?[]? exceptions = LoaderExceptions;
if (exceptions == null || exceptions.Length == 0)
Exception?[] exceptions = LoaderExceptions;
if (exceptions.Length == 0)
{
return baseValue;
}
Expand All @@ -63,10 +62,10 @@ private string CreateString(bool isMessage)
{
if (e != null)
{
text.AppendLine();
text.Append(isMessage ? e.Message : e.ToString());
text.AppendLine().Append(isMessage ? e.Message : e.ToString());
}
}

return text.ToString();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6306,11 +6306,11 @@ protected ReflectionContext() { }
}
public sealed partial class ReflectionTypeLoadException : System.SystemException, System.Runtime.Serialization.ISerializable
{
public ReflectionTypeLoadException(System.Type[]? classes, System.Exception?[]? exceptions) { }
public ReflectionTypeLoadException(System.Type[]? classes, System.Exception?[]? exceptions, string? message) { }
public System.Exception?[]? LoaderExceptions { get { throw null; } }
public ReflectionTypeLoadException(System.Type?[]? classes, System.Exception?[]? exceptions) { }
public ReflectionTypeLoadException(System.Type?[]? classes, System.Exception?[]? exceptions, string? message) { }
public System.Exception?[] LoaderExceptions { get { throw null; } }
public override string Message { get { throw null; } }
public System.Type[]? Types { get { throw null; } }
public System.Type?[] Types { get { throw null; } }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public override string ToString() { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static void NullArgumentsNoNullPointerException()
ReflectionTypeLoadException rtle = new ReflectionTypeLoadException(null, null, "Null arguments");
Assert.NotNull(rtle.ToString());
Assert.NotNull(rtle.Message);
Assert.Null(rtle.LoaderExceptions);
Assert.Null(rtle.Types);
Assert.Empty(rtle.LoaderExceptions);
Assert.Empty(rtle.Types);
}
}
}