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