akkadotnet/Hyperion

Exception serializer fails to serialize AggregateException

huzaifak opened this issue · 2 comments

Version Information
Version of Akka.NET?
1.4.25
Which Akka.NET Modules?
Akka.Serialization.HyperionSerializer

Describe the bug
Akka.Serialization.HyperionSerializer fails to Serialize AggregateException within a Message. After message is dieselized the InnerExceptions is not being populated.

Another variation of the same issue observed only when using remote actors and messaging is that the exception.Message property is also not set properly and a System.NullReferenceException is thrown.

To Reproduce**

         using (var system = ActorSystem.Create("sys", ConfigurationFactory.ParseString(@"                   
           akka.actor {
                    serializers.hyperion = ""Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion""
                    serialization-bindings {                           
          ""System.Object"" = hyperion           
      }                 
       }             
       ")))           
           {
            var message = new Message(1, new Exception("custom"));                
            var serializer = system.Serialization.FindSerializerFor(message);
            var binary = serializer.ToBinary(message);                
            var msg = (Message)serializer.FromBinary(binary, null);
           
            var aggMessage = new Message(1, new AggregateException(new List<Exception> { new Exception("1"), new Exception("2") }));
            var serializer1 = system.Serialization.FindSerializerFor(aggMessage);
            var binary1 = serializer.ToBinary(aggMessage);
            var aggMsg1 = (Message)serializer.FromBinary(binary1, null);
            if (((AggregateException)aggMsg1.Reason).InnerExceptions.Count != 2)
                throw new ApplicationException("exception is not the same");
        }

**Expected behavior**
The exception should be reserialized with two innerexceptions

**Environment**
Windows 10 Enterprise
.Net Core 3.1

assigned to @Arkatufus

AggregateException is not supported out of the box, we need to add a specialized serializer for this.