From 50da5688dcfbd5f8e15bdcd3cb96d7553595be1a Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Thu, 5 Oct 2017 16:55:25 +0200 Subject: [PATCH] Make more exceptions serializable, fix typeforwards and add one missing serialization field --- .../Reflection/ReflectionTypeLoadException.cs | 10 +++++++++ .../shared/System/Security/SecurityException.cs | 24 +++++++++++++++++++++- .../System/Threading/LockRecursionException.cs | 2 +- .../System/Threading/SemaphoreFullException.cs | 2 +- .../shared/System/TimeZoneNotFoundException.cs | 2 +- src/mscorlib/src/System/MissingMemberException.cs | 9 +++----- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs b/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs index 0e86d34..a411387 100644 --- a/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs +++ b/src/mscorlib/shared/System/Reflection/ReflectionTypeLoadException.cs @@ -6,6 +6,8 @@ using System.Runtime.Serialization; namespace System.Reflection { + [Serializable] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class ReflectionTypeLoadException : SystemException, ISerializable { public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions) @@ -24,9 +26,17 @@ namespace System.Reflection HResult = HResults.COR_E_REFLECTIONTYPELOAD; } + private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + LoaderExceptions = (Exception[])(info.GetValue("Exceptions", typeof(Exception[]))); + } + public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); + info.AddValue("Types", null, typeof(Type[])); + info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[])); } public Type[] Types { get; } diff --git a/src/mscorlib/shared/System/Security/SecurityException.cs b/src/mscorlib/shared/System/Security/SecurityException.cs index 51a23b1..61504c3 100644 --- a/src/mscorlib/shared/System/Security/SecurityException.cs +++ b/src/mscorlib/shared/System/Security/SecurityException.cs @@ -11,6 +11,13 @@ namespace System.Security [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class SecurityException : SystemException { + private const string DemandedName = "Demanded"; + private const string GrantedSetName = "GrantedSet"; + private const string RefusedSetName = "RefusedSet"; + private const string DeniedName = "Denied"; + private const string PermitOnlyName = "PermitOnly"; + private const string UrlName = "Url"; + public SecurityException() : base(SR.Arg_SecurityException) { @@ -47,11 +54,26 @@ namespace System.Security protected SecurityException(SerializationInfo info, StreamingContext context) : base(info, context) { + Demanded = (string)info.GetValueNoThrow(DemandedName, typeof(string)); + GrantedSet = (string)info.GetValueNoThrow(GrantedSetName, typeof(string)); + RefusedSet = (string)info.GetValueNoThrow(RefusedSetName, typeof(string)); + DenySetInstance = (string)info.GetValueNoThrow(DeniedName, typeof(string)); + PermitOnlySetInstance = (string)info.GetValueNoThrow(PermitOnlyName, typeof(string)); + Url = (string)info.GetValueNoThrow(UrlName, typeof(string)); } public override string ToString() => base.ToString(); - public override void GetObjectData(SerializationInfo info, StreamingContext context) => base.GetObjectData(info, context); + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue(DemandedName, Demanded, typeof(string)); + info.AddValue(GrantedSetName, GrantedSet, typeof(string)); + info.AddValue(RefusedSetName, RefusedSet, typeof(string)); + info.AddValue(DeniedName, DenySetInstance, typeof(string)); + info.AddValue(PermitOnlyName, PermitOnlySetInstance, typeof(string)); + info.AddValue(UrlName, Url, typeof(string)); + } public object Demanded { get; set; } public object DenySetInstance { get; set; } diff --git a/src/mscorlib/shared/System/Threading/LockRecursionException.cs b/src/mscorlib/shared/System/Threading/LockRecursionException.cs index ac7c1b6..c76c7a5 100644 --- a/src/mscorlib/shared/System/Threading/LockRecursionException.cs +++ b/src/mscorlib/shared/System/Threading/LockRecursionException.cs @@ -8,7 +8,7 @@ using System.Runtime.Serialization; namespace System.Threading { [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + [System.Runtime.CompilerServices.TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class LockRecursionException : System.Exception { public LockRecursionException() diff --git a/src/mscorlib/shared/System/Threading/SemaphoreFullException.cs b/src/mscorlib/shared/System/Threading/SemaphoreFullException.cs index 883e167..18558b1 100644 --- a/src/mscorlib/shared/System/Threading/SemaphoreFullException.cs +++ b/src/mscorlib/shared/System/Threading/SemaphoreFullException.cs @@ -8,7 +8,7 @@ using System.Runtime.Serialization; namespace System.Threading { [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + [System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class SemaphoreFullException : SystemException { public SemaphoreFullException() : base(SR.Threading_SemaphoreFullException) diff --git a/src/mscorlib/shared/System/TimeZoneNotFoundException.cs b/src/mscorlib/shared/System/TimeZoneNotFoundException.cs index 5eccfd5..f83c644 100644 --- a/src/mscorlib/shared/System/TimeZoneNotFoundException.cs +++ b/src/mscorlib/shared/System/TimeZoneNotFoundException.cs @@ -7,7 +7,7 @@ using System.Runtime.Serialization; namespace System { [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + [System.Runtime.CompilerServices.TypeForwardedFrom("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class TimeZoneNotFoundException : Exception { public TimeZoneNotFoundException() diff --git a/src/mscorlib/src/System/MissingMemberException.cs b/src/mscorlib/src/System/MissingMemberException.cs index 95ad711..ba16b27 100644 --- a/src/mscorlib/src/System/MissingMemberException.cs +++ b/src/mscorlib/src/System/MissingMemberException.cs @@ -12,12 +12,8 @@ =============================================================================*/ -using System; using System.Runtime.Serialization; using System.Runtime.CompilerServices; -using System.Globalization; -using System.Runtime.Versioning; -using System.Diagnostics.Contracts; namespace System { @@ -45,8 +41,8 @@ namespace System protected MissingMemberException(SerializationInfo info, StreamingContext context) : base(info, context) { - ClassName = (string)info.GetString("MMClassName"); - MemberName = (string)info.GetString("MMMemberName"); + ClassName = info.GetString("MMClassName"); + MemberName = info.GetString("MMMemberName"); Signature = (byte[])info.GetValue("MMSignature", typeof(byte[])); } @@ -80,6 +76,7 @@ namespace System { base.GetObjectData(info, context); info.AddValue("MMClassName", ClassName, typeof(string)); + info.AddValue("MMMemberName", MemberName, typeof(string)); info.AddValue("MMSignature", Signature, typeof(byte[])); } -- 2.7.4