0

I am trying to implement a plugin framework in C# where each plugin is loaded in its own AppDomain. I am having issues where the it seems that the remoting layer between AppDomains is garbage collecting my plugin instances. Each plugin inherits from this class:

public class PluginRefObject : MarshalByRefObject{
    public override object InitializeLifetimeService() {
        return null;
    }
}

Which I thought would give the object an infinite lifetime. However, the plugins seem to work for a little bit and then suddenly I get a RemotingException with an error message:

Object 'longhexstring.rem' has been disconnected or does not exist at the server

Which, from Googling, I believe means that the GC has deleted my remote object. Do I have to do something else to keep this object alive?

spectacularbob
  • 3,080
  • 2
  • 20
  • 41
  • Possible answer: http://stackoverflow.com/a/6339701/1186321 – denvercoder9 Apr 29 '16 at 19:23
  • Yeah, I saw that one. The links are bad and the posted .chm files wont open – spectacularbob Apr 29 '16 at 19:28
  • Apologies; I believe this might be helpful: https://msdn.microsoft.com/en-us/library/23bk23zc(v=vs.85).aspx – denvercoder9 Apr 29 '16 at 19:38
  • @spectacularbob I got the .chm files to open by right clicking on the file, going to properties, then clicking "Unblock". Before I did that I could see the Contents but nothing else (which is dumb, how did I get *any* info from the file if it was blocked?), but after Unblocking I could read the whole file. – Quantic Apr 29 '16 at 19:41

1 Answers1

0

It turns out that an Exception was being thrown in my plugin, causing the AppDomain to be unloaded.

It was a bit of a tricky bug though. My plugin registered a TcpChannel and there was a point where I wanted the TcpChannel disconnected via ChannelServices.UnregisterChannel(). Apparently the thread running the channel was still going and asynchronously threw an ObjectDisposedException the next time it tried to access the channel.

After Googling, it seems that there is no clean way to kill a TcpChannel and the best solution that I have found for cleaning up a channel in another AppDomain is just to unload the AppDomain

spectacularbob
  • 3,080
  • 2
  • 20
  • 41