By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,165 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,165 IT Pros & Developers. It's quick & easy.

load and unload assembly (System.AppDomain)

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.