C# – .Net Remoting – Serialisation of Delegates


I have written a custom remoting formatter sink for an established application. The formatter appears to work for most cases until I try to use it to call a remote method to which I pass a call-back to a CAO. At this point I get a SerializationException indicating that I am trying to serialise the CAO, which is obviously not what I want to do. The CAO inherits from MBRO and object lifetimes do not come into play at this stage.

Does anyone know how I can serialise the incoming IMessage in my formatter in such a way as to preserve the reference to the CAO? I assume that I need to walk the object graph, converting the CAO to an ObjRef which can then be serialised but my problem is more fundamental as I do not have a concrete 'Message' to serialise, only an IMessage. I would prefer not to use reflection.

I am aware of WCF, but do not wish to migrate to it at this stage as the application is quite large.

Best Solution

There's an excellent article on Codeproject that may provide you with the answers you are looking for. Implementing events/delegates in remoting is very tricky and the workaround is also tricky to implement. The best site to read up on this is this dude, Ingo Rammer who wrote and authored an excellent book on remoting. I have used GenuineChannels in the past to circumvent the usage of event handling limitation found in the standard .NET remoting and it does work. However GenuineChannels seems to be in trouble already...

Hope this helps, Best regards, Tom.