473,698 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

load and unload assembly (System.AppDoma in)

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.AppDomai n local_AppDomain ;
sCONTROLInterfa ce.sCONTROLInte rface local_Interface Object;
System.Reflecti on.Assembly local_Assembly;
object local_Object;
local_AppDomain =
System.AppDomai n.CreateDomain( "DynamicDomain" );
local_Assembly =
local_AppDomain .Load(System.Re flection.Assemb lyName.GetAssem blyName(@"C:\te mp\PlugIn\xyz.d ll"));
local_Object = local_Assembly. CreateInstance( "xyz.cls1") ;

If I try to add a AppDomainSetup, it does not work at all ...
System.AppDomai nSetup local_AppDomain Setup;
System.AppDomai n local_AppDomain ;
sCONTROLInterfa ce.sCONTROLInte rface local_Interface Object;
System.Reflecti on.Assembly local_Assembly;
object local_Object;
local_AppDomain Setup = new AppDomainSetup( );
local_AppDomain Setup.Applicati onBase = "file:///" +
@"C:\temp\PlugI n";
local_AppDomain =
System.AppDomai n.CreateDomain( "DynamicDomain" , null, local_AppDomain Setup);
local_Object = local_AppDomain .CreateInstance ("xyz",
"xyz.cls1") ;

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

Best regards
Frank Uray

Mar 29 '06 #1
3 22142
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.Creat eDomain("HELLO" );
AssemblyName extName = new AssemblyName();
extName.CodeBas e = "file://C:\\temp\\A.dll ";
Assembly extDll=extDom.L oad(extName);
Type extType=extDll. GetExportedType s()[0];
object extObj = _ExtDom.CreateI nstanceAndUnwra p(extDll.FullNa me,
extType.FullNam e);

Laura

"Frank Uray" <Fr*******@disc ussions.microso ft.com> ha scritto nel messaggio
news:E0******** *************** ***********@mic rosoft.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.AppDomai n local_AppDomain ;
sCONTROLInterfa ce.sCONTROLInte rface
local_Interface Object;
System.Reflecti on.Assembly local_Assembly;
object local_Object;
local_AppDomain =
System.AppDomai n.CreateDomain( "DynamicDomain" );
local_Assembly =
local_AppDomain .Load(System.Re flection.Assemb lyName.GetAssem blyName(@"C:\te mp\PlugIn\xyz.d ll"));
local_Object =
local_Assembly. CreateInstance( "xyz.cls1") ;

If I try to add a AppDomainSetup, it does not work at all ...
System.AppDomai nSetup local_AppDomain Setup;
System.AppDomai n local_AppDomain ;
sCONTROLInterfa ce.sCONTROLInte rface
local_Interface Object;
System.Reflecti on.Assembly local_Assembly;
object local_Object;
local_AppDomain Setup = new AppDomainSetup( );
local_AppDomain Setup.Applicati onBase = "file:///" +
@"C:\temp\PlugI n";
local_AppDomain =
System.AppDomai n.CreateDomain( "DynamicDomain" , null,
local_AppDomain Setup);
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.Creat eDomain("HELLO" );
AssemblyName extName = new AssemblyName();
extName.CodeBas e = "file://C:\\temp\\A.dll ";
Assembly extDll=extDom.L oad(extName);
Type extType=extDll. GetExportedType s()[0];
object extObj = _ExtDom.CreateI nstanceAndUnwra p(extDll.FullNa me,
extType.FullNam e);

Laura

"Frank Uray" <Fr*******@disc ussions.microso ft.com> ha scritto nel messaggio
news:E0******** *************** ***********@mic rosoft.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.AppDomai n local_AppDomain ;
sCONTROLInterfa ce.sCONTROLInte rface
local_Interface Object;
System.Reflecti on.Assembly local_Assembly;
object local_Object;
local_AppDomain =
System.AppDomai n.CreateDomain( "DynamicDomain" );
local_Assembly =
local_AppDomain .Load(System.Re flection.Assemb lyName.GetAssem blyName(@"C:\te mp\PlugIn\xyz.d ll"));
local_Object =
local_Assembly. CreateInstance( "xyz.cls1") ;

If I try to add a AppDomainSetup, it does not work at all ...
System.AppDomai nSetup local_AppDomain Setup;
System.AppDomai n local_AppDomain ;
sCONTROLInterfa ce.sCONTROLInte rface
local_Interface Object;
System.Reflecti on.Assembly local_Assembly;
object local_Object;
local_AppDomain Setup = new AppDomainSetup( );
local_AppDomain Setup.Applicati onBase = "file:///" +
@"C:\temp\PlugI n";
local_AppDomain =
System.AppDomai n.CreateDomain( "DynamicDomain" , null,
local_AppDomain Setup);
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*******@disc ussions.microso ft.com> ha scritto nel messaggio
news:8A******** *************** ***********@mic rosoft.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.Creat eDomain("HELLO" );
AssemblyName extName = new AssemblyName();
extName.CodeBas e = "file://C:\\temp\\A.dll ";
Assembly extDll=extDom.L oad(extName);
Type extType=extDll. GetExportedType s()[0];
object extObj = _ExtDom.CreateI nstanceAndUnwra p(extDll.FullNa me,
extType.FullNam e);

Laura

"Frank Uray" <Fr*******@disc ussions.microso ft.com> ha scritto nel
messaggio
news:E0******** *************** ***********@mic rosoft.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.AppDomai n local_AppDomain ;
> sCONTROLInterfa ce.sCONTROLInte rface
> local_Interface Object;
> System.Reflecti on.Assembly local_Assembly;
> object local_Object;
> local_AppDomain =
> System.AppDomai n.CreateDomain( "DynamicDomain" );
> local_Assembly =
> local_AppDomain .Load(System.Re flection.Assemb lyName.GetAssem blyName(@"C:\te mp\PlugIn\xyz.d ll"));
> local_Object =
> local_Assembly. CreateInstance( "xyz.cls1") ;
>
>
>
> If I try to add a AppDomainSetup, it does not work at all ...
> System.AppDomai nSetup local_AppDomain Setup;
> System.AppDomai n local_AppDomain ;
> sCONTROLInterfa ce.sCONTROLInte rface
> local_Interface Object;
> System.Reflecti on.Assembly local_Assembly;
> object local_Object;
> local_AppDomain Setup = new AppDomainSetup( );
> local_AppDomain Setup.Applicati onBase = "file:///" +
> @"C:\temp\PlugI n";
> local_AppDomain =
> System.AppDomai n.CreateDomain( "DynamicDomain" , null,
> local_AppDomain Setup);
> 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
1672
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 current code:
3
11506
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 ASP.NET. In brief I will explain: I want to create one Application domain, and call one assembly in that created application domain, and excute some methods/functions of that calling assembly and unload the application domain. All these things...
2
8489
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 very beautifully but then I would like to unload the Dll after running the ITextFormat procedure. Any ideas about doing this? I was told that it had something to do with creating a new AppDomain ... Any help would be appreciated.
2
10846
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. When trying to delete the DLL file I get an exception that access is denied. When trying to copy over the DLL file, I get an exception that it is being used by another process.
2
1584
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 questions concerns the loading of the assembly. Since there is no way to unload the assembly, what happens if a assembly I have loaded does not contain any classes that implement my interface? Does the assembly just hang around until the app ends? Does...
0
969
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 information, etc... until I realized that was actually locking the files on the common drive where the updated app is located. I know the solution to this is to load the assembly into another appdomain, then check and unload it, but I can't seem to...
0
546
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, run a method in it, and than close it. The question would be: How is the right way to do it ????
2
1275
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 deserialize the object. More information is needed.". I don't know how to fix this problem. Pls help me. Thanks. This is my code in C# public static object CreateInstance(string path) { AppDomain extDom = AppDomain.CreateDomain("HELLO"); AssemblyName...
2
1423
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 ‘Load(assmblyRef)’ method of AppDomain class, assembly is loaded but DLL file locked. I try to read DLL in byte array and load assembly calling Load(byte) method. All are pretty, but in contrast to calling Load(assmblyRef)’ method, calling...
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.