I have a plugin-based application, where each plugin is subclass of UserControl in the main settings dialog of the application.
So, for each plugin that is loaded, the system queries the plugin for
it's
settings page. The plugin creates an instance and returns a reference.
This works good for now, but I want to change my system so that each
plugin loads in a separate appdomain, so that i can unload the plugins at
run-time and all memory associated with the .dll etc also get unloaded.
The only thing that stops me is that this UserControl that the plugin
returns a reference to cannot be moved accross the appdomain. As soon as
the UserControl is added to a panel in the main settings dialog, an
exception is thrown:
An unhandled exception of type
'System.Runtime.Remoting.RemotingException'
occurred in mscorlib.dll
Additional information: Remoting cannot find field parent on type
System.Windows.Forms.Control.
I have been searching for a solution to this problem, but it seems like
this simply is not possible.
So, my question is this:
What do you guys think is the best way to get around this

Cross AppDomain
-JW
Unfortunately Controls cannot be hosted in a form from a different AppDomain. I had a similar problem. In my case, I used Reflection to create a Form in the child AppDomain, and then hosted the control in that Form. I then again used Reflection to show the form.
However, from what you're saying, you want a settings form that has controls in it from different AppDomains, so I doubt this solution would work for you.
KillerBoy
What I did was create an assembly that had a controller class with a public method that created a form, created a control, and hosted the control in the form. It also had interfaces to allow the form to hook to the control for things like closing the form and suchlike.
The plugin had to include the relevant assembly in order to implement the interfaces required by the system. When creating the plugin, I'd create my controller class in the new AppDomain, and invoke it's method. Thus, the form creation, plugin creation, and hosting all happenned in the plugin's AppDomain.
ChasP
Thank you very much.
I have another question.
How do you create a copy of the form in other AddDomain When I reflect the form, an exception is thrown which is "can not reflect on the private field on the object which in other AppDomain"
thanks