473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Setting Control's parent cross AppDomain.

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(asse mblyofcontrol2,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

Jun 17 '06 #1
2 3475
Hello Burgazon,

I think that the problem is exactly in the MarshalByRefObject, because CLR
marshal assemblies by value not by ref (because they are copied between the
domaind)
And don't forget to set Serialized attribute for the marshaled object

B> Hi,
B>
B> I encountered the following problem when trying to set control parent
B> when the control reside in a different AppDomain.
B>
B> Here is the pseudo code descibing the problem:
B> pay attention that both controls inherits from UserControl which
B> inherites
B> (indirectly)from MarshalByRefObject.
B> class Control1:UserControl
B> {
B> AppDOmainSetup setup = new AppDomainSetup();
B> //code that initialize the setup...
B> AppDomain newAppDomain =
B> AppDomain.CreateDomain("MyDomain",null,setup);
B>
B> Control c2 =
B> (Control)newAppDomain.CreateINstanceAndUnwrap(asse mblyofcontrol2,Cont
B> rol2);
B>
B> this.Controls.Add(c2); //<===Exception (see message content below)
B>
B> }
B>
B> class Control2:UserControl //this control reside in a different
B> assembly
B> {
B> }
B> The Exception message is:
B> exception the message is
B> The type System.Windows.Forms.Form+ControlCollection in Assembly
B> System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
B> PublicKeyToken=b77a5c561934e089 is not marked as serializable.
B> I tried to mark Control2 as Serializable but it didn't help :-( Any
B> suggestion?
B>
B> Thanks,
B> Burgazon
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jun 17 '06 #2
Hi Michael and Thank you for the quick response,
Itried to do what you've suggsted but it didn't work still getting the same
message.
It looks that theparents collection is not marked as serialized so it can't
be marsheled.
Do you have any other suggestions?
Thanks
"Michael Nemtsev" wrote:
Hello Burgazon,

I think that the problem is exactly in the MarshalByRefObject, because CLR
marshal assemblies by value not by ref (because they are copied between the
domaind)
And don't forget to set Serialized attribute for the marshaled object

B> Hi,
B>
B> I encountered the following problem when trying to set control parent
B> when the control reside in a different AppDomain.
B>
B> Here is the pseudo code descibing the problem:
B> pay attention that both controls inherits from UserControl which
B> inherites
B> (indirectly)from MarshalByRefObject.
B> class Control1:UserControl
B> {
B> AppDOmainSetup setup = new AppDomainSetup();
B> //code that initialize the setup...
B> AppDomain newAppDomain =
B> AppDomain.CreateDomain("MyDomain",null,setup);
B>
B> Control c2 =
B> (Control)newAppDomain.CreateINstanceAndUnwrap(asse mblyofcontrol2,Cont
B> rol2);
B>
B> this.Controls.Add(c2); //<===Exception (see message content below)
B>
B> }
B>
B> class Control2:UserControl //this control reside in a different
B> assembly
B> {
B> }
B> The Exception message is:
B> exception the message is
B> The type System.Windows.Forms.Form+ControlCollection in Assembly
B> System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
B> PublicKeyToken=b77a5c561934e089 is not marked as serializable.
B> I tried to mark Control2 as Serializable but it didn't help :-( Any
B> suggestion?
B>
B> Thanks,
B> Burgazon
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Jun 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MatthewRoberts | last post by:
Howdy All, I am having difficulty with two-way communication across AppDomains in an attempt to dynamically script applications. Everything works as expected, except when using ByRef parameters....
16
by: Marina | last post by:
Hi, I am trying to find the minimum security settings to allow a windows control embedded in IE have full trust. If I give the entire Intranet zone full trust, this works. However, this is...
8
by: Richard L Rosenheim | last post by:
I have a dataset containing a parent table related to a child table. The child table contains an ID field (which is configured as autonumber in the datatable), the ID of the parent, plus some...
11
by: Alexander Walker | last post by:
Hello I would like to write a method that allows me to pass a reference to an instance of a class, the name of a property of that class and a value to set that property to, the method would then...
3
by: Mark Rae | last post by:
Hi, Just a general quickie on setting properties of user controls from the parent form. Let's say I have a user control called note.ascx which displays a datagrid. That datagrid is populated...
1
by: Basti | last post by:
Hello, I'm working with .Net 2.0. I tried to get attributes of an unloaded assembly. So, the sole way I know is to create a new child application domain, in this app domain I load the assembly,...
0
by: zb | last post by:
Here is the page architecture: Page loads multiple user controls (including nested user controls) dynamically based on parameters provided into place holders. Note: The page only has the logic to...
1
by: Linda Liu[MSFT] | last post by:
Hi Moondaddy, I downloaded your sample project and run it on my machine. I did see the problem on my side. The image drawn in the Button is not as clear as that one drawn in the Image control. ...
1
by: nicerun | last post by:
I'm using the Application_Start event at Global.asax.cs to invoke thread that do some job. I know that Application_Start event occurs when the very first request to Web Application received. -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.