Setting Control's parent cross AppDomains

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I encountered the following problem when trying to set control parent when
the control reside in a different AppDomain.

Here is the pseudo code descibing the problem:
pay attention that both controls inherits from UserControl which inherites
(indirectly)from MarshalByRefObject.


class Control1:UserControl
{

AppDOmainSetup setup = new AppDomainSetup();
//code that initialize the setup...

AppDomain newAppDomain = AppDomain.CreateDomain("MyDomain",null,setup);

Control c2 =
(Control)newAppDomain.CreateINstanceAndUnwrap(assemblyofcontrol2,Control2);

this.Controls.Add(c2); //<===Exception (see message content below)

}


class Control2:UserControl //this control reside in a different assembly
{
}

The Exception message is:
exception the message is
The type System.Windows.Forms.Form+ControlCollection in Assembly
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.

I tried to mark Control2 as Serializable but it didn't help :-(
Any suggestion?

Thanks,
Burgazon
 
Hi,

Looks like the Control2 class communicates back to its parent collection,
and since the ControlCollection class is neither serializable nor derived
from MarshalByRefObject, this communication fails. I would really consider
moving away from multi-appdomain scenario in this case.
 
Thank you for the quick response.
I will try to change parts of my architecture.
Thank you (again)
 
Back
Top