Skip to content

Commit 36ece7a

Browse files
Numpsypiksel
authored andcommitted
Merge PR #369: Make the custom exception types serializable
* Make all the custom exception classes serializable. * Add unit tests for exception serialization.
1 parent ffe5115 commit 36ece7a

12 files changed

+276
-0
lines changed

src/ICSharpCode.SharpZipLib/BZip2/BZip2Exception.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib.BZip2
45
{
56
/// <summary>
67
/// BZip2Exception represents exceptions specific to BZip2 classes and code.
78
/// </summary>
9+
[Serializable]
810
public class BZip2Exception : SharpZipBaseException
911
{
1012
/// <summary>
@@ -32,5 +34,21 @@ public BZip2Exception(string message, Exception innerException)
3234
: base(message, innerException)
3335
{
3436
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the BZip2Exception class with serialized data.
40+
/// </summary>
41+
/// <param name="info">
42+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43+
/// object data about the exception being thrown.
44+
/// </param>
45+
/// <param name="context">
46+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
47+
/// about the source or destination.
48+
/// </param>
49+
protected BZip2Exception(SerializationInfo info, StreamingContext context)
50+
: base(info, context)
51+
{
52+
}
3553
}
3654
}

src/ICSharpCode.SharpZipLib/Core/Exceptions/SharpZipBaseException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib
45
{
@@ -8,6 +9,7 @@ namespace ICSharpCode.SharpZipLib
89
/// </summary>
910
/// <remarks>NOTE: Not all exceptions thrown will be derived from this class.
1011
/// A variety of other exceptions are possible for example <see cref="ArgumentNullException"></see></remarks>
12+
[Serializable]
1113
public class SharpZipBaseException : Exception
1214
{
1315
/// <summary>
@@ -36,5 +38,21 @@ public SharpZipBaseException(string message, Exception innerException)
3638
: base(message, innerException)
3739
{
3840
}
41+
42+
/// <summary>
43+
/// Initializes a new instance of the SharpZipBaseException class with serialized data.
44+
/// </summary>
45+
/// <param name="info">
46+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
47+
/// object data about the exception being thrown.
48+
/// </param>
49+
/// <param name="context">
50+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
51+
/// about the source or destination.
52+
/// </param>
53+
protected SharpZipBaseException(SerializationInfo info, StreamingContext context)
54+
: base(info, context)
55+
{
56+
}
3957
}
4058
}

src/ICSharpCode.SharpZipLib/Core/Exceptions/StreamDecodingException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib
45
{
56
/// <summary>
67
/// Indicates that an error occured during decoding of a input stream due to corrupt
78
/// data or (unintentional) library incompability.
89
/// </summary>
10+
[Serializable]
911
public class StreamDecodingException : SharpZipBaseException
1012
{
1113
private const string GenericMessage = "Input stream could not be decoded";
@@ -28,5 +30,21 @@ public StreamDecodingException(string message) : base(message) { }
2830
/// <param name="message">A message describing the exception.</param>
2931
/// <param name="innerException">The inner exception</param>
3032
public StreamDecodingException(string message, Exception innerException) : base(message, innerException) { }
33+
34+
/// <summary>
35+
/// Initializes a new instance of the StreamDecodingException class with serialized data.
36+
/// </summary>
37+
/// <param name="info">
38+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
39+
/// object data about the exception being thrown.
40+
/// </param>
41+
/// <param name="context">
42+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
43+
/// about the source or destination.
44+
/// </param>
45+
protected StreamDecodingException(SerializationInfo info, StreamingContext context)
46+
: base(info, context)
47+
{
48+
}
3149
}
3250
}

src/ICSharpCode.SharpZipLib/Core/Exceptions/StreamUnsupportedException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib
45
{
56
/// <summary>
67
/// Indicates that the input stream could not decoded due to known library incompability or missing features
78
/// </summary>
9+
[Serializable]
810
public class StreamUnsupportedException : StreamDecodingException
911
{
1012
private const string GenericMessage = "Input stream is in a unsupported format";
@@ -27,5 +29,21 @@ public StreamUnsupportedException(string message) : base(message) { }
2729
/// <param name="message">A message describing the exception.</param>
2830
/// <param name="innerException">The inner exception</param>
2931
public StreamUnsupportedException(string message, Exception innerException) : base(message, innerException) { }
32+
33+
/// <summary>
34+
/// Initializes a new instance of the StreamUnsupportedException class with serialized data.
35+
/// </summary>
36+
/// <param name="info">
37+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
38+
/// object data about the exception being thrown.
39+
/// </param>
40+
/// <param name="context">
41+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
42+
/// about the source or destination.
43+
/// </param>
44+
protected StreamUnsupportedException(SerializationInfo info, StreamingContext context)
45+
: base(info, context)
46+
{
47+
}
3048
}
3149
}

src/ICSharpCode.SharpZipLib/Core/Exceptions/UnexpectedEndOfStreamException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib
45
{
56
/// <summary>
67
/// Indicates that the input stream could not decoded due to the stream ending before enough data had been provided
78
/// </summary>
9+
[Serializable]
810
public class UnexpectedEndOfStreamException : StreamDecodingException
911
{
1012
private const string GenericMessage = "Input stream ended unexpectedly";
@@ -27,5 +29,21 @@ public UnexpectedEndOfStreamException(string message) : base(message) { }
2729
/// <param name="message">A message describing the exception.</param>
2830
/// <param name="innerException">The inner exception</param>
2931
public UnexpectedEndOfStreamException(string message, Exception innerException) : base(message, innerException) { }
32+
33+
/// <summary>
34+
/// Initializes a new instance of the UnexpectedEndOfStreamException class with serialized data.
35+
/// </summary>
36+
/// <param name="info">
37+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
38+
/// object data about the exception being thrown.
39+
/// </param>
40+
/// <param name="context">
41+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
42+
/// about the source or destination.
43+
/// </param>
44+
protected UnexpectedEndOfStreamException(SerializationInfo info, StreamingContext context)
45+
: base(info, context)
46+
{
47+
}
3048
}
3149
}

src/ICSharpCode.SharpZipLib/Core/Exceptions/ValueOutOfRangeException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib
45
{
56
/// <summary>
67
/// Indicates that a value was outside of the expected range when decoding an input stream
78
/// </summary>
9+
[Serializable]
810
public class ValueOutOfRangeException : StreamDecodingException
911
{
1012
/// <summary>
@@ -44,5 +46,21 @@ private ValueOutOfRangeException()
4446
private ValueOutOfRangeException(string message, Exception innerException) : base(message, innerException)
4547
{
4648
}
49+
50+
/// <summary>
51+
/// Initializes a new instance of the ValueOutOfRangeException class with serialized data.
52+
/// </summary>
53+
/// <param name="info">
54+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
55+
/// object data about the exception being thrown.
56+
/// </param>
57+
/// <param name="context">
58+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
59+
/// about the source or destination.
60+
/// </param>
61+
protected ValueOutOfRangeException(SerializationInfo info, StreamingContext context)
62+
: base(info, context)
63+
{
64+
}
4765
}
4866
}

src/ICSharpCode.SharpZipLib/Core/InvalidNameException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib.Core
45
{
56
/// <summary>
67
/// InvalidNameException is thrown for invalid names such as directory traversal paths and names with invalid characters
78
/// </summary>
9+
[Serializable]
810
public class InvalidNameException : SharpZipBaseException
911
{
1012
/// <summary>
@@ -31,5 +33,21 @@ public InvalidNameException(string message) : base(message)
3133
public InvalidNameException(string message, Exception innerException) : base(message, innerException)
3234
{
3335
}
36+
37+
/// <summary>
38+
/// Initializes a new instance of the InvalidNameException class with serialized data.
39+
/// </summary>
40+
/// <param name="info">
41+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
42+
/// object data about the exception being thrown.
43+
/// </param>
44+
/// <param name="context">
45+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
46+
/// about the source or destination.
47+
/// </param>
48+
protected InvalidNameException(SerializationInfo info, StreamingContext context)
49+
: base(info, context)
50+
{
51+
}
3452
}
3553
}

src/ICSharpCode.SharpZipLib/GZip/GZipException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib.GZip
45
{
56
/// <summary>
67
/// GZipException represents exceptions specific to GZip classes and code.
78
/// </summary>
9+
[Serializable]
810
public class GZipException : SharpZipBaseException
911
{
1012
/// <summary>
@@ -32,5 +34,21 @@ public GZipException(string message, Exception innerException)
3234
: base(message, innerException)
3335
{
3436
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the GZipException class with serialized data.
40+
/// </summary>
41+
/// <param name="info">
42+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43+
/// object data about the exception being thrown.
44+
/// </param>
45+
/// <param name="context">
46+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
47+
/// about the source or destination.
48+
/// </param>
49+
protected GZipException(SerializationInfo info, StreamingContext context)
50+
: base(info, context)
51+
{
52+
}
3553
}
3654
}

src/ICSharpCode.SharpZipLib/Lzw/LzwException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib.Lzw
45
{
56
/// <summary>
67
/// LzwException represents exceptions specific to LZW classes and code.
78
/// </summary>
9+
[Serializable]
810
public class LzwException : SharpZipBaseException
911
{
1012
/// <summary>
@@ -32,5 +34,21 @@ public LzwException(string message, Exception innerException)
3234
: base(message, innerException)
3335
{
3436
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the LzwException class with serialized data.
40+
/// </summary>
41+
/// <param name="info">
42+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43+
/// object data about the exception being thrown.
44+
/// </param>
45+
/// <param name="context">
46+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
47+
/// about the source or destination.
48+
/// </param>
49+
protected LzwException(SerializationInfo info, StreamingContext context)
50+
: base(info, context)
51+
{
52+
}
3553
}
3654
}

src/ICSharpCode.SharpZipLib/Tar/TarException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib.Tar
45
{
56
/// <summary>
67
/// TarException represents exceptions specific to Tar classes and code.
78
/// </summary>
9+
[Serializable]
810
public class TarException : SharpZipBaseException
911
{
1012
/// <summary>
@@ -32,5 +34,21 @@ public TarException(string message, Exception innerException)
3234
: base(message, innerException)
3335
{
3436
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the TarException class with serialized data.
40+
/// </summary>
41+
/// <param name="info">
42+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43+
/// object data about the exception being thrown.
44+
/// </param>
45+
/// <param name="context">
46+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
47+
/// about the source or destination.
48+
/// </param>
49+
protected TarException(SerializationInfo info, StreamingContext context)
50+
: base(info, context)
51+
{
52+
}
3553
}
3654
}

src/ICSharpCode.SharpZipLib/Zip/ZipException.cs

+18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace ICSharpCode.SharpZipLib.Zip
45
{
56
/// <summary>
67
/// ZipException represents exceptions specific to Zip classes and code.
78
/// </summary>
9+
[Serializable]
810
public class ZipException : SharpZipBaseException
911
{
1012
/// <summary>
@@ -32,5 +34,21 @@ public ZipException(string message, Exception innerException)
3234
: base(message, innerException)
3335
{
3436
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the ZipException class with serialized data.
40+
/// </summary>
41+
/// <param name="info">
42+
/// The System.Runtime.Serialization.SerializationInfo that holds the serialized
43+
/// object data about the exception being thrown.
44+
/// </param>
45+
/// <param name="context">
46+
/// The System.Runtime.Serialization.StreamingContext that contains contextual information
47+
/// about the source or destination.
48+
/// </param>
49+
protected ZipException(SerializationInfo info, StreamingContext context)
50+
: base(info, context)
51+
{
52+
}
3553
}
3654
}

0 commit comments

Comments
 (0)