Setting Control's parent cross AppDomains

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
 
D

Dmytro Lapshyn [MVP]

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.
 
G

Guest

Thank you for the quick response.
I will try to change parts of my architecture.
Thank you (again)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top