Skip to content

Commit

Permalink
Make all exception types serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Jun 15, 2020
1 parent 3bce28e commit 2f28225
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 27 deletions.
1 change: 1 addition & 0 deletions ref/Castle.Core-net45.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2615,6 +2615,7 @@ public class InvalidProxyConstructorArgumentsException : System.ArgumentExceptio
{
public System.Type ClassToProxy { get; }
public System.Type ProxyType { get; }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
public class MixinData
{
Expand Down
3 changes: 3 additions & 0 deletions ref/Castle.Core-netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@ public class LoggerException : System.Exception
{
public LoggerException() { }
public LoggerException(string message) { }
protected LoggerException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public LoggerException(string message, System.Exception innerException) { }
}
public enum LoggerLevel
Expand Down Expand Up @@ -2367,6 +2368,7 @@ public class ResourceException : System.Exception
{
public ResourceException() { }
public ResourceException(string message) { }
protected ResourceException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public ResourceException(string message, System.Exception innerException) { }
}
public class StaticContentResource : Castle.Core.Resource.AbstractResource
Expand Down Expand Up @@ -2595,6 +2597,7 @@ public class InvalidProxyConstructorArgumentsException : System.ArgumentExceptio
{
public System.Type ClassToProxy { get; }
public System.Type ProxyType { get; }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
public class MixinData
{
Expand Down
3 changes: 3 additions & 0 deletions ref/Castle.Core-netstandard2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@ public class LoggerException : System.Exception
{
public LoggerException() { }
public LoggerException(string message) { }
protected LoggerException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public LoggerException(string message, System.Exception innerException) { }
}
public enum LoggerLevel
Expand Down Expand Up @@ -2367,6 +2368,7 @@ public class ResourceException : System.Exception
{
public ResourceException() { }
public ResourceException(string message) { }
protected ResourceException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public ResourceException(string message, System.Exception innerException) { }
}
public class StaticContentResource : Castle.Core.Resource.AbstractResource
Expand Down Expand Up @@ -2595,6 +2597,7 @@ public class InvalidProxyConstructorArgumentsException : System.ArgumentExceptio
{
public System.Type ClassToProxy { get; }
public System.Type ProxyType { get; }
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
public class MixinData
{
Expand Down
6 changes: 0 additions & 6 deletions src/Castle.Core/Core/Logging/LoggerException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
namespace Castle.Core.Logging
{
using System;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif

#if FEATURE_SERIALIZATION
[Serializable]
#endif
public class LoggerException : Exception
{
public LoggerException()
Expand All @@ -36,10 +32,8 @@ public LoggerException(String message, Exception innerException) : base(message,
{
}

#if FEATURE_SERIALIZATION
protected LoggerException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
}
7 changes: 1 addition & 6 deletions src/Castle.Core/Core/Resource/ResourceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
namespace Castle.Core.Resource
{
using System;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif

#if FEATURE_SERIALIZATION
[Serializable]
#endif
public class ResourceException : Exception
{
public ResourceException()
Expand All @@ -35,10 +31,9 @@ public ResourceException(string message) : base(message)
public ResourceException(string message, Exception innerException) : base(message, innerException)
{
}
#if FEATURE_SERIALIZATION

protected ResourceException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
}
6 changes: 0 additions & 6 deletions src/Castle.Core/DynamicProxy/Generators/GeneratorException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
namespace Castle.DynamicProxy.Generators
{
using System;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif

#if FEATURE_SERIALIZATION
[Serializable]
#endif
public class GeneratorException : Exception
{
internal GeneratorException(string message) : base(message)
Expand All @@ -32,10 +28,8 @@ internal GeneratorException(string message, Exception innerException) : base(mes
{
}

#if FEATURE_SERIALIZATION
private protected GeneratorException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
namespace Castle.DynamicProxy
{
using System;
#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
#endif

#if FEATURE_SERIALIZATION
[Serializable]
#endif
public class InvalidMixinConfigurationException : Exception
{
internal InvalidMixinConfigurationException(string message)
Expand All @@ -33,10 +29,8 @@ internal InvalidMixinConfigurationException(string message, Exception innerExcep
{
}

#if FEATURE_SERIALIZATION
private protected InvalidMixinConfigurationException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,33 @@
namespace Castle.DynamicProxy
{
using System;
using System.Runtime.Serialization;

#if FEATURE_SERIALIZATION
[Serializable]
#endif
public class InvalidProxyConstructorArgumentsException : ArgumentException
{
internal InvalidProxyConstructorArgumentsException(string message, Type proxyType, Type classToProxy) : base(message)
{
ProxyType = proxyType;
ClassToProxy = classToProxy;
ProxyType = proxyType;
}

private protected InvalidProxyConstructorArgumentsException(SerializationInfo info, StreamingContext context) : base(info, context)
{
// Binary serialization on .NET Core does not support `Type`,
// so we need to make do with type name strings:
ClassToProxy = Type.GetType(info.GetString("classToProxy"));
ProxyType = Type.GetType(info.GetString("proxyType"));
}

public Type ClassToProxy { get; private set; }
public Type ProxyType { get; private set; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("classToProxy", ClassToProxy.AssemblyQualifiedName);
info.AddValue("proxyType", ProxyType.AssemblyQualifiedName);
}
}
}

0 comments on commit 2f28225

Please sign in to comment.