Deserialization of Generic class throws InvalidCastException
marko-savic opened this issue · 2 comments
I'm using Akka.Serialization.Hyperion 1.1.3.32-beta,
On receiver side i never receive message when message contains Maybe<MyCustomClass>
due deserialization exception.
Is this problem may be related to Hyperion or i need to register custom serializer or something i'm missing?
Stack trace:
System.InvalidCastException: Unable to cast object of type 'Common.Types.Maybe1[Domain.Models.Vending.Devices.States.DoorSensorState]' to type 'Domain.Models.Vending.Devices.States.DoorSensorState'.\r\n at lambda_method(Closure , Stream , DeserializerSession )\r\n at lambda_method(Closure , Stream , DeserializerSession )\r\n at Hyperion.SerializerFactories.EnumerableSerializerFactory.<>c__DisplayClass5_0.<BuildSerializer>b__1(Stream stream, DeserializerSession session)\r\n at lambda_method(Closure , Stream , DeserializerSession )\r\n at Hyperion.Serializer.Deserialize[T](Stream stream)\r\n at Akka.Serialization.HyperionSerializer.FromBinary(Byte[] bytes, Type type)\r\n at Akka.Serialization.Serialization.Deserialize(Byte[] bytes, Int32 serializerId, String manifest)\r\n at Akka.Remote.DefaultMessageDispatcher.Dispatch(IInternalActorRef recipient, Address recipientAddress, SerializedMessage message, IActorRef senderOption)\r\n at Akka.Remote.EndpointReader.<Reading>b__11_1(InboundPayload inbound)\r\n at lambda_method(Closure , Object , Action
1 , Action1 , Action
1 )\r\n at Akka.Tools.MatchHandler.PartialHandlerArgumentsCapture4.Handle(T value)\r\n at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, PartialAction
1 partialAction)\r\n at Akka.Actor.UntypedActor.Receive(Object message)\r\n at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)\r\n at Akka.Actor.ActorCell.ReceiveMessage(Object message)\r\n at Akka.Actor.ActorCell.Invoke(Envelope envelope)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Akka.Actor.ActorCell.HandleFailed(Failed f)\r\n at Akka.Actor.ActorCell.SysMsgInvokeAll(EarliestFirstSystemMessageList messages, Int32 currentState)",
@marko-savic could you isolate this exception and provide some reproducible example?
I have tried simple test only with latest Hyperion and struct Maybe<T>
. Everything seems to work correct. However when using Akka.Serialization.Hyperion 1.1.3.32-beta within actor system i got System.InvalidCastException.
So simple working example is communication between two actors in CLR. Just turn on serialization for every message:
akka { actor { serialize-messages = on } }
And send one message like this:
class TestMessage { Maybe<MyTestClass> testField = Maybe<MyTestClass>.From(new MyTestClass()); } public MyTestClass { }
where Maybe<T>
is struct provided in a file.
Maybe.cs