title: How would I give a delegate infinite life the same way as a proxy when doing cross-app-domain development?
body: <p><b>Background</b><br/>
  I developed a custom plugin architecture using a derivation of the <a href="http://msdn.microsoft.com/en-us/library/ee817669.aspx" rel="nofollow noreferrer">Observer/Event Pattern</a> and bits and pieces of code from the following:</p>
  
  <p><a href="http://www.codeproject.com/KB/cs/dynamicpluginmanager.aspx" rel="nofollow noreferrer">Code Project: Plugin Manager</a><br/><a href="http://msdn.microsoft.com/en-us/library/system.appdomain%28v=VS.80%29.aspx" rel="nofollow noreferrer">Microsoft: AppDomains</a><br/><a href="http://www.danielsoltyka.com/index.php/2009/08/10/developing-a-simple-plugin-architecture-in-c/" rel="nofollow noreferrer">Daniel Soltyka: Simple Plugin</a><br/></p>
  
  <p>I had an issue in the past. Each plugin is loaded in it's own app domain so that they cannot see each other nor can they see things in the main app domain (we have proprietary data in our application we do not want plugin developers to see). A proxy is created with each new app domain/plugin in order to communicate with the plugin from the main app. The issue was that the proxy became disconnected after 5 minutes or so. This was easily solved by overriding the <code>InitializeLifetimeService()</code> method and returning null (<a href="http://www.codeguru.com/forum/archive/index.php/t-337542.html" rel="nofollow noreferrer">reference</a>).</p>
  
  <p><b>The Problem</b></p>
  
  <p>The issue now is on the other side of things. I am "registering" callback functions on the plugin side by sending delegates from the main app side to each plugin. The plugins can then call these delegates which will call the functions in the main app. The delegates, though, apparently get disconnected just like the proxies in the above explanation.</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/2410221/appdomain-and-marshalbyrefobject-life-time-how-to-avoid-remotingexception">this</a> on SO and the <code>ClientSponsor.Register()</code> method sounds great, but it needs a "MarshalByRefObject" as parameter. Mine are delegates, so no dice.</p>
  
  <p>I want to find a way to keep my main app delegates connected across app domains the way the plugin proxies are.</p>
  
  <p>Any ideas?</p>