   [.net] [VICTORY]Did I misunderstood how to use Remoting?
  I've been working on a game that uses Remoting for it's networking. I coded it according to a 2-tier model and I used interfaces to share between client/server.However, my controller class gives me serialization errors. I wonder if the problem is because my controller class also has references to the UI component, a bunch of lists, etc.    public class AssholeServer : MarshalByRefObject, IServer    {   private List<Player> players = new List<Player>();   private List<Player> spectators = new List<Player>();   private Player winner = null;   private CardDeck deck = new CardDeck(BackSide.CardHand);   private PlayStack stack = new PlayStack();   private GameState gameState = GameState.Idle;Do I need to move all the remoting code into a different class, and use delegates/events to propagate things through to the UI?Toolmaker[Edited by - Toolmaker on January 19, 2006 12:44:22 PM]
  There are a few possibilities:1. I'm not sure whether the generics (List<>) serialize (are you using soap/xml formatter or the binary?)2. UI parts ALLWAYS need their OWN thread so yes use events/delegate BUT allways use the invokemethod method of the form they are on.3. Anything being accessed via the remoted object also has to be a marshalbyrefobject!4... and moreShow us the exact errormessage orprovide a download of more code...CheersErno   ;  I was looking at the List<> docs a few days ago and noticed it was serializable. But that depends on whether your player class is also serializable; the whole class hierarchy from that class has to be serializable for serialization to succeed.   ;  I did some rewriting of the code, and discovered Something Bad(tm). When I call server.Join(this), I get a SerializationException:Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.This is ALL the code:    public class Client : MarshalByRefObject, IClient    {   private string name;   private IServer server = null;   private GameState gameState = GameState.Idle;   #region Events   public event ConnectedEventHandler Connected;   public event UserEventHandler UserJoined;   public event UserEventHandler UserLeft;   public void OnConnected(ConnectionEventArgs e)   {  if (Connected != null) Connected(this, e);   }   public void OnUserJoined(UserEventArgs e)   {  if (UserJoined != null) UserJoined(this, e);   }   public void OnUserLeft(UserEventArgs e)   {  if (UserLeft != null) UserLeft(this, e);   }   #endregion    public Client()   {   }   #region IClient Members   public void Connect(string url, string name)   {  this.name = name;  url = "tcp://" + url + ":4000/AssholeServer";  IServer server = (IServer)Activator.GetObject(typeof(IServer), url);  IClient ic = this;  server.Join(ic);  IPlayer[] playerList = server.GetPlayerList();  OnConnected(new ConnectionEventArgs(playerList));   }   public string GetName()   {  return name;   }   public void ClientJoined(IPlayer player)   {  OnUserJoined(new UserEventArgs(player));   }   public void ClientLeft(IPlayer player)   {  OnUserLeft(new UserEventArgs(player));   }   public void GameStarted()   {  throw new Exception("The method or operation is not implemented.");   }   public void SelectTopCards()   {  throw new Exception("The method or operation is not implemented.");   }   public void Turn(IPlayer player)   {  throw new Exception("The method or operation is not implemented.");   }   public void ClearPlayStack()   {  throw new Exception("The method or operation is not implemented.");   }   public void UpdateDeck(int numCards)   {  throw new Exception("The method or operation is not implemented.");   }   public void CardsPlayed(IPlayer player, Toolmaker.Cards.Card[] cards)   {  throw new Exception("The method or operation is not implemented.");   }   #endregion    }I get the same exception on my old code, which is weird. I first thought it had to do with the GUI components, but apparantly, it's not. I derive my class from an interface, which should solve the problem for stuff like the GUI components(Casting down to the interface, should prevent those items from serializing).EDIT: It got worse another bit, when I call GetPlayerList() before calling Join, I get an exception, that it cannot find the server assembly. That is stupid, because I use interfaces. According to the tutorials I used, using the interfaces should be enough to NOT require the assemblies of the server.MOAR EDIT: I placed breakpoints, and it seems that the function DOES get called on the server, and returns properly.Any ideas? I'm growing desperate of Remoting...Toolmaker[Edited by - Toolmaker on January 18, 2006 6:40:04 PM];  This sounds exactly like a problem I had, and I solved it by following steps described in the following tutorial.  Basically, you have to pass some different flags to serialize object references.  If you're lucky it's the same problem.http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconautomaticdeserializationinnetremoting.asp   ;Quote:Original post by Geronimo2000This sounds exactly like a problem I had, and I solved it by following steps described in the following tutorial.  Basically, you have to pass some different flags to serialize object references.  If you're lucky it's the same problem.http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconautomaticdeserializationinnetremoting.aspOmg, thanks! I bumped up your rating, that fixed 1 problem [grin].Now I have a different problem occuring, I get an exception on this line:IPlayer[] playerList = server.GetPlayerList();The exception I get is:Unable to find assembly 'SwedishAssholeServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.Ok, I fixed it by casting all the objects down to their interface(I was sending an array).Toolmaker