0

I have made 2 Akka.NET solutions in the hope of testing out Remoting on a simple hello world example, however, I keep getting a Disassociated exception when the communication attempt is made. I have reason to believe that this is because of the shared class Greet which should be a message that both systems should understand. Unfortunately, they don't. How can I fix this?

This is the code of the "Server" application:

namespace Shared
{
    public class Greet
    {
        public string Who { get; set; }

        public Greet(string who)
        {
            Who = who;
        }
    }
}


namespace AkkaTest
{

    using Shared;

    class GreeterActor : ReceiveActor
    {
        public GreeterActor()
        {
            Receive<Greet>(x => Console.WriteLine("Hello {0}", x.Who));
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var config =  ConfigurationFactory.ParseString(@"
                akka {
                    actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""

                    remote {
                        helios.tcp {
                            port = 9099
                            hostname = 127.0.0.1
                        }
                    }
                }
            ");

            using (ActorSystem system = ActorSystem.Create("MyServer", config))
            {
                system.ActorOf<GreeterActor>("greeter");

                Console.ReadLine();

                system.Shutdown();
            }
        }
    }
}

Here is the code for the client:

namespace Shared
{
    public class Greet
    {
        public string Who { get; set; }

        public Greet(string who)
        {
            Who = who;
        }
    }
}

namespace AkkaTest
{
    using Shared;

    class Program
    {
        static void Main(string[] args)
        {
            var config = ConfigurationFactory.ParseString(@"
                akka {
                    actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""

                    remote {
                        helios.tcp {
                            port = 9090
                            hostname = 127.0.0.1
                        }
                    }
                }
            ");

            using (var system = ActorSystem.Create("MyClient", config))
            {
                //get a reference to the remote actor
                var greeter = system
                    .ActorSelection("akka.tcp://MyServer@127.0.0.1:9099/user/greeter");
                //send a message to the remote actor
                greeter.Tell(new Greet("Roger"));

                Console.ReadLine();
            }
        }
    }
}

EDIT: Putting both client and server in the same solution but different projects, and the GreetingActor and Greet in a shared projects fixes the issues. However, I would like to have completely separate solutions.

Marin
  • 861
  • 1
  • 11
  • 27

1 Answers1

2

If you are using Greet messages on both sides, you need to provide some way do share this message schema between them. Usually this is done as a separate project shared between other projects or solutions.

While default Akka.NET serializer uses fully qualified type name with assembly to serialize/deserialize messages, it's also version tolerant - you can modify message schema and gradually update it's assembly node by node.

Other option is to use custom serializer. This way you'll be able to determine by yourself, how message will be serialized/deserialized on both ends. You can read more about this topic here.

Bartosz Sypytkowski
  • 7,463
  • 19
  • 36
  • So, I can add a shared project to both solutions and it would work? I will give a try. tnx – Marin Dec 16 '15 at 12:27