473,394 Members | 2,160 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,394 software developers and data experts.

load and unload assembly (System.AppDomain)

Hi all

I have a problem with loading a assembly ...
I am trying to do the following:
- I have a directory with a dll (assembly) in it (not the currect dir.)
- I am trying to load this assembly, run a method in it, and than close it.
The question would be: How is the right way to do it ????

The following way works, exept that I need to copy the dll into the
current directory and I am unable to unload it ...
System.AppDomain local_AppDomain;
sCONTROLInterface.sCONTROLInterface local_InterfaceObject;
System.Reflection.Assembly local_Assembly;
object local_Object;
local_AppDomain =
System.AppDomain.CreateDomain("DynamicDomain");
local_Assembly =
local_AppDomain.Load(System.Reflection.AssemblyNam e.GetAssemblyName(@"C:\temp\PlugIn\xyz.dll"));
local_Object = local_Assembly.CreateInstance("xyz.cls1");

If I try to add a AppDomainSetup, it does not work at all ...
System.AppDomainSetup local_AppDomainSetup;
System.AppDomain local_AppDomain;
sCONTROLInterface.sCONTROLInterface local_InterfaceObject;
System.Reflection.Assembly local_Assembly;
object local_Object;
local_AppDomainSetup = new AppDomainSetup();
local_AppDomainSetup.ApplicationBase = "file:///" +
@"C:\temp\PlugIn";
local_AppDomain =
System.AppDomain.CreateDomain("DynamicDomain", null, local_AppDomainSetup);
local_Object = local_AppDomain.CreateInstance("xyz",
"xyz.cls1");

PLEASE HELP ... !!!!
Thanks for any comment !

Best regards
Frank Uray

Mar 29 '06 #1
3 22099
What errors do you get?
Are you talking about a full trust app or something else?

I use this code to load dll's in appdomains and it works for me:

extDom = AppDomain.CreateDomain("HELLO");
AssemblyName extName = new AssemblyName();
extName.CodeBase = "file://C:\\temp\\A.dll";
Assembly extDll=extDom.Load(extName);
Type extType=extDll.GetExportedTypes()[0];
object extObj = _ExtDom.CreateInstanceAndUnwrap(extDll.FullName,
extType.FullName);

Laura

"Frank Uray" <Fr*******@discussions.microsoft.com> ha scritto nel messaggio
news:E0**********************************@microsof t.com...
Hi all

I have a problem with loading a assembly ...
I am trying to do the following:
- I have a directory with a dll (assembly) in it (not the currect dir.)
- I am trying to load this assembly, run a method in it, and than close
it.
The question would be: How is the right way to do it ????

The following way works, exept that I need to copy the dll into the
current directory and I am unable to unload it ...
System.AppDomain local_AppDomain;
sCONTROLInterface.sCONTROLInterface
local_InterfaceObject;
System.Reflection.Assembly local_Assembly;
object local_Object;
local_AppDomain =
System.AppDomain.CreateDomain("DynamicDomain");
local_Assembly =
local_AppDomain.Load(System.Reflection.AssemblyNam e.GetAssemblyName(@"C:\temp\PlugIn\xyz.dll"));
local_Object =
local_Assembly.CreateInstance("xyz.cls1");

If I try to add a AppDomainSetup, it does not work at all ...
System.AppDomainSetup local_AppDomainSetup;
System.AppDomain local_AppDomain;
sCONTROLInterface.sCONTROLInterface
local_InterfaceObject;
System.Reflection.Assembly local_Assembly;
object local_Object;
local_AppDomainSetup = new AppDomainSetup();
local_AppDomainSetup.ApplicationBase = "file:///" +
@"C:\temp\PlugIn";
local_AppDomain =
System.AppDomain.CreateDomain("DynamicDomain", null,
local_AppDomainSetup);
local_Object = local_AppDomain.CreateInstance("xyz",
"xyz.cls1");

PLEASE HELP ... !!!!
Thanks for any comment !

Best regards
Frank Uray

Mar 29 '06 #2
Hi Laura

Thanks a lot for your answer !

It is very bad but I cant get this to work ... :-((

I can create the AppDomain.
I can create the AssemblyName
Because the directory of the external dll is not the current
directory the Load than fails ... it does not find the dll ... of corse
because it is looking in the wrong directory ...

.... it really drives me crazy ... :-)))
Do you have any ideas about that??

Best regards
Frank

"Laura T." wrote:
What errors do you get?
Are you talking about a full trust app or something else?

I use this code to load dll's in appdomains and it works for me:

extDom = AppDomain.CreateDomain("HELLO");
AssemblyName extName = new AssemblyName();
extName.CodeBase = "file://C:\\temp\\A.dll";
Assembly extDll=extDom.Load(extName);
Type extType=extDll.GetExportedTypes()[0];
object extObj = _ExtDom.CreateInstanceAndUnwrap(extDll.FullName,
extType.FullName);

Laura

"Frank Uray" <Fr*******@discussions.microsoft.com> ha scritto nel messaggio
news:E0**********************************@microsof t.com...
Hi all

I have a problem with loading a assembly ...
I am trying to do the following:
- I have a directory with a dll (assembly) in it (not the currect dir.)
- I am trying to load this assembly, run a method in it, and than close
it.
The question would be: How is the right way to do it ????

The following way works, exept that I need to copy the dll into the
current directory and I am unable to unload it ...
System.AppDomain local_AppDomain;
sCONTROLInterface.sCONTROLInterface
local_InterfaceObject;
System.Reflection.Assembly local_Assembly;
object local_Object;
local_AppDomain =
System.AppDomain.CreateDomain("DynamicDomain");
local_Assembly =
local_AppDomain.Load(System.Reflection.AssemblyNam e.GetAssemblyName(@"C:\temp\PlugIn\xyz.dll"));
local_Object =
local_Assembly.CreateInstance("xyz.cls1");

If I try to add a AppDomainSetup, it does not work at all ...
System.AppDomainSetup local_AppDomainSetup;
System.AppDomain local_AppDomain;
sCONTROLInterface.sCONTROLInterface
local_InterfaceObject;
System.Reflection.Assembly local_Assembly;
object local_Object;
local_AppDomainSetup = new AppDomainSetup();
local_AppDomainSetup.ApplicationBase = "file:///" +
@"C:\temp\PlugIn";
local_AppDomain =
System.AppDomain.CreateDomain("DynamicDomain", null,
local_AppDomainSetup);
local_Object = local_AppDomain.CreateInstance("xyz",
"xyz.cls1");

PLEASE HELP ... !!!!
Thanks for any comment !

Best regards
Frank Uray


Mar 29 '06 #3
Ok, I think you need to make an assembly loader .exe that you execute in the
foreign appdomain passing it the assembly dll name as a parameter. Just a
stub .exe.

For more info, check out these:

http://blogs.msdn.com/suzcook/archiv.../16/57188.aspx
http://blogs.msdn.com/brada/archive/.../16/49974.aspx
http://blogs.msdn.com/suzcook/archiv.../12/57169.aspx
http://www.gotdotnet.com/team/clr/Ap...#_Toc514058497

Laura

"Frank Uray" <Fr*******@discussions.microsoft.com> ha scritto nel messaggio
news:8A**********************************@microsof t.com...
Hi Laura

Thanks a lot for your answer !

It is very bad but I cant get this to work ... :-((

I can create the AppDomain.
I can create the AssemblyName
Because the directory of the external dll is not the current
directory the Load than fails ... it does not find the dll ... of corse
because it is looking in the wrong directory ...

... it really drives me crazy ... :-)))
Do you have any ideas about that??

Best regards
Frank

"Laura T." wrote:
What errors do you get?
Are you talking about a full trust app or something else?

I use this code to load dll's in appdomains and it works for me:

extDom = AppDomain.CreateDomain("HELLO");
AssemblyName extName = new AssemblyName();
extName.CodeBase = "file://C:\\temp\\A.dll";
Assembly extDll=extDom.Load(extName);
Type extType=extDll.GetExportedTypes()[0];
object extObj = _ExtDom.CreateInstanceAndUnwrap(extDll.FullName,
extType.FullName);

Laura

"Frank Uray" <Fr*******@discussions.microsoft.com> ha scritto nel
messaggio
news:E0**********************************@microsof t.com...
> Hi all
>
> I have a problem with loading a assembly ...
> I am trying to do the following:
> - I have a directory with a dll (assembly) in it (not the currect dir.)
> - I am trying to load this assembly, run a method in it, and than close
> it.
> The question would be: How is the right way to do it ????
>
>
>
> The following way works, exept that I need to copy the dll into the
> current directory and I am unable to unload it ...
> System.AppDomain local_AppDomain;
> sCONTROLInterface.sCONTROLInterface
> local_InterfaceObject;
> System.Reflection.Assembly local_Assembly;
> object local_Object;
> local_AppDomain =
> System.AppDomain.CreateDomain("DynamicDomain");
> local_Assembly =
> local_AppDomain.Load(System.Reflection.AssemblyNam e.GetAssemblyName(@"C:\temp\PlugIn\xyz.dll"));
> local_Object =
> local_Assembly.CreateInstance("xyz.cls1");
>
>
>
> If I try to add a AppDomainSetup, it does not work at all ...
> System.AppDomainSetup local_AppDomainSetup;
> System.AppDomain local_AppDomain;
> sCONTROLInterface.sCONTROLInterface
> local_InterfaceObject;
> System.Reflection.Assembly local_Assembly;
> object local_Object;
> local_AppDomainSetup = new AppDomainSetup();
> local_AppDomainSetup.ApplicationBase = "file:///" +
> @"C:\temp\PlugIn";
> local_AppDomain =
> System.AppDomain.CreateDomain("DynamicDomain", null,
> local_AppDomainSetup);
> local_Object = local_AppDomain.CreateInstance("xyz",
> "xyz.cls1");
>
>
>
> PLEASE HELP ... !!!!
> Thanks for any comment !
>
> Best regards
> Frank Uray
>


Mar 30 '06 #4

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

Similar topics

3
by: Andy | last post by:
Hi, i tried to load an assembly to an appdomain. The data output is correctly but the assembly is still in use after unloading the appdomain... What am I doing wrong? Please help! My...
3
by: Raveendra | last post by:
Hi! I am trying to create one new Application Domain and calling one Assembly in that created Application Domain. It is working fine with stand alone application. But I need to do the same with...
2
by: Patrick Blackman | last post by:
I have a program that search the application path for all the Dll that implement a certain interface IText ,when a Dll with the interface is found ,I run a method called IText.Format() which works...
2
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload....
2
by: Chris Dunaway | last post by:
I am using reflection to load an assembly dynamically at runtime. If there are classes in the assembly that implement a particular interface, I put an entry in a list for later use. My...
0
by: marfi95 | last post by:
Hi all, I'm writing some code to automatically update my application when changes have been made. I had it all working by using the LoadFrom method of an assembly and checking the version...
0
by: Frank Uray | last post by:
Hi all I have a problem with loading a assembly ... I am trying to do the following: - I have a directory with a dll (assembly) in it (not the currect dir.) - I am trying to load this assembly,...
2
by: linhnc | last post by:
Hi all, Because I have to load and unload an assembly, so I try to create a new appdomain and load the assembly into it. But it throws an exception with the message "Insufficient state to...
2
by: =?Utf-8?B?UGFi?= | last post by:
Hello, I am confused with load assembly in AppDomain. I created ASP Web application, same business logic is realized in custom DLLs, and I need to load ones in my application. If I use...
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.