473,387 Members | 1,404 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,387 software developers and data experts.

Is it possible to make the UserControl derived class run in another AppDomain?

Supposing I have a class "UserControl1 : System.Windows.Forms.UserControl"
in an Assembly "UI.dll", now I create an Application project and want to use
the "UserControl1" in another AppDomain,

private void CreateUIInAnotherDomain()
{
UI.UserControl1 ui =
(UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI. dll", "UI.UserControl1");

this.Controls.Add(ui);
}

Obviously, the obove code is wrong, so Is it possible to make the
UserControl derived class run in another AppDomain?
Thank you!
Nov 16 '05 #1
3 3940
In order to cross AppDomains you must use Remoting, and there are only two
options:
- derive from MarshalByRefObject, which UserControl doesn't
- be serializable, which UserControl is not

However, you *could* implement ISerializable on your UserControl-derived
class and handle the serialization/deserialization yourself. However, it
would be quite tricky, since you'd have to recreate window handles and
suchlike.

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Supposing I have a class "UserControl1 : System.Windows.Forms.UserControl"
in an Assembly "UI.dll", now I create an Application project and want to
use the "UserControl1" in another AppDomain,

private void CreateUIInAnotherDomain()
{
UI.UserControl1 ui =
(UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI. dll",
"UI.UserControl1");

this.Controls.Add(ui);
}

Obviously, the obove code is wrong, so Is it possible to make the
UserControl derived class run in another AppDomain?
Thank you!

Nov 16 '05 #2
Yes, can you give me more hint and if there is any documentation about this
? Thank you very much!
Regards,
ZhangZQ
"Sean Hederman" <us***@blogentry.com> wrote in message
news:d0**********@ctb-nnrp2.saix.net...
In order to cross AppDomains you must use Remoting, and there are only two
options:
- derive from MarshalByRefObject, which UserControl doesn't
- be serializable, which UserControl is not

However, you *could* implement ISerializable on your UserControl-derived
class and handle the serialization/deserialization yourself. However, it
would be quite tricky, since you'd have to recreate window handles and
suchlike.

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Supposing I have a class "UserControl1 :
System.Windows.Forms.UserControl" in an Assembly "UI.dll", now I create
an Application project and want to use the "UserControl1" in another
AppDomain,

private void CreateUIInAnotherDomain()
{
UI.UserControl1 ui =
(UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI. dll",
"UI.UserControl1");

this.Controls.Add(ui);
}

Obviously, the obove code is wrong, so Is it possible to make the
UserControl derived class run in another AppDomain?
Thank you!


Nov 16 '05 #3
"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Yes, can you give me more hint and if there is any documentation about
this ? Thank you very much!
I personally have never marshalled a control across app domain boundaries,
and don't think it's a particularly good idea. Wouldn't it better to send
objects containing the information you require across the boundary? The
other side can then use that information to create the relevant controls. In
that case you can just decorate your objects with the SerializableAttribute.

If you're determined to go the UserControl route, google for "Implementing
ISerializable". Note that when you implement this interface, you must also
implement a constructor of the form: MyClass(SerializationInfo info,
StreamingContext context) {}. This constructor handles deserialization. I
don't know if you'll have to handle any special coding in order to implement
the private properties of the UserControl. Possible not. If not, you could
just serialize the public properties across. With a control, these are quite
a few, so you can expect a lot of work...
Regards,
ZhangZQ
"Sean Hederman" <us***@blogentry.com> wrote in message
news:d0**********@ctb-nnrp2.saix.net...
In order to cross AppDomains you must use Remoting, and there are only
two options:
- derive from MarshalByRefObject, which UserControl doesn't
- be serializable, which UserControl is not

However, you *could* implement ISerializable on your UserControl-derived
class and handle the serialization/deserialization yourself. However, it
would be quite tricky, since you'd have to recreate window handles and
suchlike.

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Supposing I have a class "UserControl1 :
System.Windows.Forms.UserControl" in an Assembly "UI.dll", now I create
an Application project and want to use the "UserControl1" in another
AppDomain,

private void CreateUIInAnotherDomain()
{
UI.UserControl1 ui =
(UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI. dll",
"UI.UserControl1");

this.Controls.Add(ui);
}

Obviously, the obove code is wrong, so Is it possible to make the
UserControl derived class run in another AppDomain?
Thank you!



Nov 16 '05 #4

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

Similar topics

0
by: BestNews | last post by:
OS: XP ..Net= framework = 1.0.3705 VS.Net IDE = 7.0.9466 1. I used an ActiveX control in C# client Application. After executing Aximp of ActiveX control. I derived a class from the AxHost.
0
by: SDCII | last post by:
I have a UserControl derived class containing a textbox that wires the 'Validating' event. The textbox remains in focus when I cancel the validation, however another Usercontrol derived class on...
3
by: Brad Navarro | last post by:
OK, I may be asking for the impossible, but I'll give it a shot: For a case like this: using System.Data.SqlClient; abstract class Base { private SqlConnection DBConnect; Base(string...
3
by: Tony Maresca | last post by:
Hi. I have a class derived from a UserControl, that I want to allow others to derive controls from. I don't want them to design the base class (which is derived from a UserControl). I know that...
3
by: ZhangZQ | last post by:
Supposing I have a class "UserControl1 : System.Windows.Forms.UserControl" in an Assembly "UI.dll", now I create an Application project and want to use the "UserControl1" in another AppDomain, ...
11
by: Crirus | last post by:
I need to derive the Windows.Forms.Control 2 times so I design a class like this Public Class BMControl Inherits System.Windows.Forms.UserControl Public Class MapControl Inherits BMControl
7
by: steve.kaye | last post by:
I am writing a number of controls which use inheritance and I have a problem that I do not know how to solve. It's best if I describe the class structure I want. Grid - derives from UserControl...
3
by: navyliu | last post by:
I have raised a discussion about assembly unloading.But we can't get a final solution. Since we cannot unlaod a assembly,Is there any reference about this indicate that this problem won't make...
8
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.