Skip to content

Commit 9ff1bcd

Browse files
sungam3rPliner
authored andcommitted
Make EasyNetQ exceptions really serializable
Fixes #705 (#953)
1 parent 098d126 commit 9ff1bcd

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace EasyNetQ.Tests
5+
{
6+
public class SerializationTests
7+
{
8+
[Fact]
9+
public void Should_Deserialize_Exceptions()
10+
{
11+
var str1 = Newtonsoft.Json.JsonConvert.SerializeObject(new EasyNetQException("blablabla"));
12+
var ex1 = Newtonsoft.Json.JsonConvert.DeserializeObject<EasyNetQException>(str1);
13+
ex1.Message.Should().Be("blablabla");
14+
15+
var str2 = Newtonsoft.Json.JsonConvert.SerializeObject(new EasyNetQResponderException("Ooops"));
16+
var ex2 = Newtonsoft.Json.JsonConvert.DeserializeObject<EasyNetQResponderException>(str2);
17+
ex2.Message.Should().Be("Ooops");
18+
}
19+
}
20+
}

Source/EasyNetQ/EasyNetQException.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace EasyNetQ
45
{
6+
[Serializable]
57
public class EasyNetQException : Exception
68
{
7-
public EasyNetQException() {}
8-
public EasyNetQException(string message) : base(message) {}
9-
public EasyNetQException(string format, params string[] args) : base(string.Format(format, args)) {}
10-
public EasyNetQException(string message, Exception inner) : base(message, inner) {}
9+
public EasyNetQException() { }
10+
public EasyNetQException(string message) : base(message) { }
11+
public EasyNetQException(string format, params object[] args) : base(string.Format(format, args)) { }
12+
public EasyNetQException(string message, Exception inner) : base(message, inner) { }
13+
protected EasyNetQException(SerializationInfo info, StreamingContext context) : base(info, context) { }
1114
}
1215

16+
[Serializable]
1317
public class EasyNetQResponderException : EasyNetQException
1418
{
1519
public EasyNetQResponderException() { }
1620
public EasyNetQResponderException(string message) : base(message) { }
17-
public EasyNetQResponderException(string format, params string[] args) : base(format, args) { }
21+
public EasyNetQResponderException(string format, params object[] args) : base(format, args) { }
1822
public EasyNetQResponderException(string message, Exception inner) : base(message, inner) { }
23+
protected EasyNetQResponderException(SerializationInfo info, StreamingContext context) : base(info, context) { }
1924
}
20-
}
25+
}

0 commit comments

Comments
 (0)