I am trying to send a Record message between remote actors in Akka.FSharp, but I am getting the following serialization exception.
[WARNING][27-11-2021 16:37:25][Thread 0025][akka.tcp://Server@localhost:8001/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FClient%40localhost%3A59213-1/endpointWriter/endpointReader-akka.tcp%3A%2F%2FClient%40localhost%3A59213-1] Deserialization failed for message with serializer id [6] and manifest []. Transient association error (association remains live). Failed to deserialize payload object when deserializing ActorSelectionMessage with payload [SerializerId=-5, Manifest=] addressed to [user,serverActor]
Cause: System.Runtime.Serialization.SerializationException: Failed to deserialize payload object when deserializing ActorSelectionMessage with payload [SerializerId=-5, Manifest=] addressed to [user,serverActor]
---> System.Runtime.Serialization.SerializationException: Failed to deserialize instance of type . Could not load file or assembly 'Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
---> System.IO.FileNotFoundException: Could not load file or assembly 'Client, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Client, Culture=neutral, PublicKeyToken=null'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at Hyperion.Extensions.TypeEx.LoadTypeByName(String name, Boolean disallowUnsafeTypes)
at Hyperion.Extensions.TypeEx.<>c__DisplayClass28_0.<GetTypeFromManifestName>b__0(ByteArrayKey b)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Hyperion.Extensions.TypeEx.GetTypeFromManifestName(Stream stream, DeserializerSession session)
at Hyperion.Extensions.TypeEx.GetTypeFromManifestVersion(Stream stream, DeserializerSession session)
at Hyperion.Serializer.Deserialize[T](Stream stream)
at Akka.Serialization.HyperionSerializer.FromBinary(Byte[] bytes, Type type)
--- End of inner exception stack trace ---
at Akka.Serialization.HyperionSerializer.FromBinary(Byte[] bytes, Type type)
at Akka.Serialization.Serialization.Deserialize(Byte[] bytes, Int32 serializerId, String manifest)
at Akka.Remote.Serialization.WrappedPayloadSupport.PayloadFrom(Payload payload)
at Akka.Remote.Serialization.MessageContainerSerializer.FromBinary(Byte[] bytes, Type type)
--- End of inner exception stack trace ---
at Akka.Remote.Serialization.MessageContainerSerializer.FromBinary(Byte[] bytes, Type type)
at Akka.Serialization.Serialization.Deserialize(Byte[] bytes, Int32 serializerId, String manifest)
at Akka.Remote.MessageSerializer.Deserialize(ExtendedActorSystem system, Payload messageProtocol)
at Akka.Remote.DefaultMessageDispatcher.Dispatch(IInternalActorRef recipient, Address recipientAddress, Payload message, IActorRef senderOption)
at Akka.Remote.EndpointReader.<Reading>b__11_0(InboundPayload inbound)
Following is my code for two remote actors.
Server:
open System
open Akka
open Akka.FSharp
type Message =
| TestMessage of (int)
[<EntryPoint>]
let main argv =
let serverConfig() = Configuration.parse("""
akka {
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
serializers {
json = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
}
serialization-bindings {
"System.Object" = json
}
}
remote {
helios.tcp {
port = 8001
hostname = localhost
}
}
}
""")
let serverSystem = serverConfig() |> System.create "Server"
let serverActor (mailbox: Actor<Message>) =
let rec loop() = actor {
let! message = mailbox.Receive()
match message with
| TestMessage(num) ->
printfn "%d" num
return! loop()
}
loop()
spawn serverSystem "ServerActor" serverActor |> ignore
Console.ReadLine() |> ignore
0 // return an integer exit code
Client:
open System
open Akka
open Akka.FSharp
type Message =
| TestMessage of (int)
[<EntryPoint>]
let main argv =
let clientConfig() = Configuration.parse("""
akka {
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
serializers {
json = "Akka.Serialization.HyperionSerializer, Akka.Serialization.Hyperion"
}
serialization-bindings {
"System.Object" = json
}
}
remote {
helios.tcp {
port = 0
hostname = localhost
}
}
}
""")
let clientSystem = clientConfig() |> System.create "Client"
let serverActorRef = select ("akka.tcp://Server@localhost:8001/user/ServerActor") clientSystem
serverActorRef <! Message.TestMessage(0)
Console.ReadLine() |> ignore
0 // return an integer exit code
I have configured Akka.Serialization.Hyperion, but still, I am getting the same exception. Not sure what I am doing wrong here. Any help is appriciated.
You have declared Message in two places, and you should use dot-netty.tcp like Bent Tranberg sugguested. Below is the screenshot of a working solution:
This is what I did:
TestMessageinto a common class library to be shared!helios.tcpwithdot-netty.tcpAkka.Serialization.Hyperion