Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / May 2004

Tip: Looking for answers? Try searching our database.

Usage of AppDomain.CreateInstanceFromAndUnwrap method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vineeth Karinta - 06 May 2004 02:16 GMT
i am trying to load a Windows Form Assembly at run time to a seprate AppDomain.
I don't want that this Assembly to be loaded in the Caller Domain, so i used the metho
CreateInstanceFromAndUnwrap instead of AppDomain.Load(..
// I am passing the Control's parent through the constructor argumen
Object[] args1 = new Object[] {this}
AppDomainSetup info = new AppDomainSetup()
info.ApplicationBase = "file:///" + System.Environment.CurrentDirectory
AppDomain MyDomain = AppDomain.CreateDomain("MyDomain", null, info)
MyControl.MyControl Ctrl = (MyControl.MyControl) MyDomain.CreateInstanceFromAndUnwrap("D:\Test\MyControl.dll",MyControl.MyControl
false,BindingFlags.Public,null,args1,null,null,null)
But when i do this i get an exception thrown "Constructor on type MyControl.MyControl not found
What should be cause of this issue?

If i try to use the CreateInstanceFromAndUnwrap using the two parameters just the assembly and type, the functio
returns me the control object. But when i try to set the Parent of the control using the followin
code
Ctrl.Parent = this

then system throws an 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

What am i doing any thing wrong in this both scenarios
Or is it advisable to have a design where i can load my Windows Forms Assemblies in to a seprat
Domain and use, and later unload it

Any body please help
Janine Zhang[MSFT] - 18 May 2004 01:49 GMT
Please see Suzanne's blog:  
http://blogs.msdn.com/suzcook/archive/2003/06/12/57169.aspx

The reason for other failures is that Controls are not inherited from
MarshalByRefObject, so the program will attempt to load them into the
calling AppDomain.

In your case, you should write a wrapper class that is inherited from
MarshalByRefObject.   Create an AppDomain, do a CreateInstanceAndUnwrap on
the class and call a method on that class.  That method contains all the
code to load Winform controls, etc.

--------------------
>Thread-Topic: Usage of AppDomain.CreateInstanceFromAndUnwrap method
>thread-index: AcQzB7MclnXlF4Z1Sb6wk7Ma3fugfw==
>X-WN-Post: microsoft.public.dotnet.framework.clr
>From: =?Utf-8?B?VmluZWV0aCBLYXJpbnRh?=
<anonymous@discussions.microsoft.com>
>Subject: Usage of AppDomain.CreateInstanceFromAndUnwrap method
>Date: Wed, 5 May 2004 18:16:03 -0700
[quoted text clipped - 16 lines]
>
>i am trying to load a Windows Form Assembly at run time to a seprate AppDomain.
I don't want that this Assembly to be loaded in the Caller Domain, so i
used the method
CreateInstanceFromAndUnwrap instead of AppDomain.Load(..)
// I am passing the Control's parent through the constructor argument
Object[] args1 = new Object[] {this};
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = "file:///" + System.Environment.CurrentDirectory;
AppDomain MyDomain = AppDomain.CreateDomain("MyDomain", null, info);
MyControl.MyControl Ctrl = (MyControl.MyControl)
MyDomain.CreateInstanceFromAndUnwrap("D:\Test\MyControl.dll",MyControl.MyCon
trol,
false,BindingFlags.Public,null,args1,null,null,null);
But when i do this i get an exception thrown "Constructor on type
MyControl.MyControl not found.
What should be cause of this issue?.

If i try to use the CreateInstanceFromAndUnwrap using the two parameters
just the assembly and type, the function
returns me the control object. But when i try to set the Parent of the
control using the following
code
Ctrl.Parent = this;

then system throws an 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.

What am i doing any thing wrong in this both scenarios.
Or is it advisable to have a design where i can load my Windows Forms
Assemblies in to a seprate
Domain and use, and later unload it.

Any body please help....

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note:  For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.