Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Execute cross-app domain code

Execute cross-app domain code

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Benny_Lava
    wrote on last edited by
    #1

    Hello, This is the situation I have an assembly A (plugin) loaded into separate app domain, that assembly fires a couple of events. And i have a class B created using the default App domain. Now Class A raises and event and event handler in class B catches that event, but since it is called from another App domain (A) it cannot see variables of app domain B (all variables are null) in this case a public static object that is 100% not null on app domain B. I think i understand why the variable is null, but how do i execute event handler code in app domain B so that code executed in app domain B will see the variables initialized? I have tried CrossAppDomainDelegate but it can only call mehods that don't have any parameters, and since this is an event handler it has parameters and not standard event signature but with a custom EventArgs. How can i solve this problem. Thank you!

    B 1 Reply Last reply
    0
    • B Benny_Lava

      Hello, This is the situation I have an assembly A (plugin) loaded into separate app domain, that assembly fires a couple of events. And i have a class B created using the default App domain. Now Class A raises and event and event handler in class B catches that event, but since it is called from another App domain (A) it cannot see variables of app domain B (all variables are null) in this case a public static object that is 100% not null on app domain B. I think i understand why the variable is null, but how do i execute event handler code in app domain B so that code executed in app domain B will see the variables initialized? I have tried CrossAppDomainDelegate but it can only call mehods that don't have any parameters, and since this is an event handler it has parameters and not standard event signature but with a custom EventArgs. How can i solve this problem. Thank you!

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      Make sure the objects passed in the delegate arguments, and the result type, are either simple objects or inherit from MarshalByRefObject. You will probably need to create proxy classes for complex types in your plugin to achieve that. For example from my lobby server:

        // For remoting/cross-domain plugin purposes
        // Need to be able to do basic tasks (log, send message) from anywhere
        public class LobbyProxy: MarshalByRefObject {
            public BaseLobby lobby;
            public LobbyProxy(BaseLobby l){ this.lobby = l; }
            
            public void Log(object sender, String msg){ lobby.Log(sender, msg); }
            public MemberInfo Member(int id){ return lobby.Member(id); }
            public MemberInfo GetMember(string name){ return lobby.GetMember(name); }
            public bool MemberInGame(int member, int game){ return lobby.MemberInGame(member, game); }
            public int MemberIndexInGame(int member, int game){ return lobby.MemberIndexInGame(member, game); }
        }
        
        public class ServerLobbyProxy: LobbyProxy {
            public ServerLobby serverLobby;
            public ServerLobbyProxy(ServerLobby l) : base(l) { this.serverLobby = l; }
            public void SendMessage(int id, uint command, byte\[\] msg){ serverLobby.Server\[id\].SendMessage(command, msg); }
            public void SendMessage(int id, uint command, byte\[\] msg, byte pt){ serverLobby.Server\[id\].SendMessage(command, msg, pt); }
        }
        
        public class ClientLobbyProxy : LobbyProxy {
            public ClientLobby clientLobby;
            public ClientLobbyProxy(ClientLobby l) : base(l) { this.clientLobby = l; }
            public void SendMessage( uint command, byte\[\] msg){ clientLobby.Connection.SendMessage(command, msg); }
            public void SendMessage( uint command, byte\[\] msg, byte pt){ clientLobby.Connection.SendMessage(command, msg, pt); }
            public int MyID { get { return clientLobby.MyID; } }
            public MemberInfo Me { get { return clientLobby.Me; } }
            public void DoChat(int DefaultScope, String msg, int GameID){ clientLobby.DoChat(DefaultScope, msg, GameID); }
        }
      

      This is actually the other way around (so plugins can call methods in the main app domain) as I find that design cleaner. (Plugins are responsible for making sure that they respond to events and call whatever they need to in the main app domain, via these well defined interfaces.) But the same thing should work from the other side too.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups