From feffe6dd97dbc90c4114624a55a7cce0573bb2e8 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 12 Apr 2020 17:04:04 +0100 Subject: [PATCH] Make InvalidHeaderException serializable --- .../Tar/InvalidHeaderException.cs | 18 ++++++++++++++++++ .../Serialization/SerializationTests.cs | 1 + 2 files changed, 19 insertions(+) diff --git a/src/ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs b/src/ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs index a2e114052..9f385e425 100644 --- a/src/ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs +++ b/src/ICSharpCode.SharpZipLib/Tar/InvalidHeaderException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; namespace ICSharpCode.SharpZipLib.Tar { @@ -6,6 +7,7 @@ namespace ICSharpCode.SharpZipLib.Tar /// This exception is used to indicate that there is a problem /// with a TAR archive header. /// + [Serializable] public class InvalidHeaderException : TarException { /// @@ -33,5 +35,21 @@ public InvalidHeaderException(string message, Exception exception) : base(message, exception) { } + + /// + /// Initializes a new instance of the InvalidHeaderException class with serialized data. + /// + /// + /// The System.Runtime.Serialization.SerializationInfo that holds the serialized + /// object data about the exception being thrown. + /// + /// + /// The System.Runtime.Serialization.StreamingContext that contains contextual information + /// about the source or destination. + /// + protected InvalidHeaderException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + } } } diff --git a/test/ICSharpCode.SharpZipLib.Tests/Serialization/SerializationTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Serialization/SerializationTests.cs index 6118022e4..cb3344ae4 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Serialization/SerializationTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Serialization/SerializationTests.cs @@ -23,6 +23,7 @@ public class SerializationTests [Category("Serialization")] [TestCase(typeof(BZip2Exception))] [TestCase(typeof(GZipException))] + [TestCase(typeof(InvalidHeaderException))] [TestCase(typeof(InvalidNameException))] [TestCase(typeof(LzwException))] [TestCase(typeof(SharpZipBaseException))]