Search code examples
delegatesremoting

Passing a delegate using remoting without passing the implementation assembly


I have been stuck on this for a few days and I would ping this community for answers before I give up.

*I would like to pass a delegate from a client application to a server application across app domains using remoting. *The delegate is definition is in an Assembly which is shared between the server and client. * The delegate it self is an anonymous delegate for which the body is declared on the client side.

My problem is that when I pass the delegate over to the server, the server requires the assembly for which the delegate body is declared(one of the client assembly). Our software architecture prohibits loading the client assembly. In my head when I think about it I should be be able to pass the IL which defines the delegate over to the server, create a delegate using dyanmicMethod and execute it. If that is the case then why does .net require the assembly even when the delegate body contains simple types? Is there a way to remote an assembly without requiring the assembly where the body is declared?

PS: the reason I want to do is for performance. The delegate encapsulates multiple calls to the server. I am unable to modify the server APIs etc to do this.

Thanks fro any information


Solution

  • I don't think you can do this.

    When you pass the delegate to the server, the server will need to be able to load the definition of the class that defines the delegate, so there is no way to get a client-only anonymous method to execute on the server side.

    There is a discussion on how to work around this at this link. I don't know if you can reorganize your code to align with that pattern.

    It would be an intriguing idea to send some IL over to the other side and execute this in place, but I have no idea if that is possible. Sounds like there would be an awful lot of security and other barriers to cross to get this to work.