I'm new to Akka.NET. I have recently started to do my university project and faced the strange problem. I have two ActorSystems in two different desktop applications. In the first ActorSystem I'm sending the message ZippedAddressListMessage between two actors using Akka.Remote.
public class ZippedAddressListMessage
{
public ZippedAddressListMessage(List<string> list)
{
this.Values = list.AsReadOnly();
}
public IReadOnlyCollection<string> Values { get; private set; }
}
This works fine, but when I try to send this message to other ActorSystem, I get the huge list of errors: screenshot #1 of the console window with the error
Nevertheless, if I send a simple message that consists of only one integer, all works well. It's likely that there is a serialization problem, but I couldn't figure out how it must be solved. I've searched everywhere, but still haven't found the answer. Please, could you explain me how to solve this issue?
Actor from the first ActorSystem:
using Akka.Actor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChatMessages;
using System.Diagnostics;
using Akka.Serialization;
using Akka.Actor.Internal;
using Akka.Remote;
namespace Agent
{
public class ActorHelper: ReceiveActor
{
int N;
int fromId;
int count;
IActorRef chiefAgent;
List<recordItem> agentList;
public ActorHelper()
{
count = 0;
agentList = new List<recordItem>();
Receive<CreateHelpersMessage>(msg =>
{
chiefAgent = Sender;
fromId = msg.fromID;
N = msg.N;
for (int i = 0; i < msg.N; i++)
{
Process.Start("C:\\Users\\Artemij\\Source\\Repos\\Client\\AgentHelper\\AgentHelper\\bin\\Debug\\AgentHelper.exe",
"akka.tcp://Agent@localhost:8000/user/AgentActor/ActorHelper" + " " + i);
}
});
Receive<NewAgentHelperMessage>(msg =>
{
Console.WriteLine(msg.name + " " + Sender.Path.ToString() + " || " + (count+1) + "/" + N);
agentList.Add(new recordItem(fromId + count, msg.name, Sender));
count++;
Context.Watch(Sender);
if (count == N)
{
chiefAgent.Tell(new AddressListMessage(agentList), Self);
}
});
Receive<AddressListMessage>(msg =>
{
Console.WriteLine("All is ready");
List<string> temp = new List<string>();
foreach (recordItem i in msg.Values)
{
temp.Add(i.ID + " " + i.name + " " + Serialization.SerializedActorPath(i.address));
}
foreach (recordItem i in agentList)
{
Console.WriteLine(i.address);
//PROBLEM HERE!
i.address.Tell(new ZippedAddressListMessage(temp), Self);
}
});
}
}
}
Actor from other ActorSystem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Akka.Actor;
using ChatMessages;
using System.Diagnostics;
namespace AgentHelper
{
class AgentHelperActor: ReceiveActor
{
int priority;
ActorSelection seniorAgentActor;
List<recordItem> fullList;
public AgentHelperActor(string addressSenior, string rank)
{
fullList = new List<recordItem>();
seniorAgentActor = Context.ActorSelection(addressSenior);
Int32.TryParse(rank, out priority);
seniorAgentActor.Tell(new NewAgentHelperMessage("agent"+priority, ""), Self);
//RECEIVING A LIST!!
Receive<ZippedAddressListMessage>(msg =>
{
Console.WriteLine("The entire list");
});
Receive<NewAgentHelperMessage>(msg =>
{
Console.WriteLine(msg.name);
});
}
public void updateList(IReadOnlyCollection<recordItem> list)
{
fullList = new List<recordItem>(list);
foreach (recordItem i in fullList)
{
Console.WriteLine(i.ToString());
}
}
}
}
UPDATED: Here's a screenshot of the error at the beginning. screenshot #2 of the console window with the error It writes that format of System.String[] is not compatible with JSON serialization.