473,395 Members | 1,677 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,395 software developers and data experts.

problem with releasing loaded dll

Hi,

I try to load an assembly, use it and then release it. I am wondering if
there is a way to release the assembly?
I've read that if you use the current AppDomain this is not possible, so you
have to create a second domain to load the assembly, use it and unload the
domain. I use the following code:

//I have an dll called test in the current directory that I want to load
//The assembly is not domain-neutral
string lAssemblyName = Directory.GetCurrentDirectory() + @"\Test.dll";

//Create application domain setup and set the base directory to the current
directory
AppDomainSetup AppDomSetup = new AppDomainSetup();
AppDomSetup.ApplicationBase = Directory.GetCurrentDirectory();

//Create the new domain and load the assembly
AppDomain NewDomain = AppDomain.CreateDomain("SecDomain", null, AppDomSetup);
NewDomain.Load("Test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

//After using it (not shown here), unload the new domain
AppDomain.Unload(NewDomain);

//Try to copy a dll over the unloaded dll (with overwrite = true);
File.Copy(@"C:\Test1.dll", lAssemblyName, true);
This gives the following exception:
The process cannot access the file '..\Test.dll' because it is being used by
another process.

So the dll is still not released. Is there a way to release it instead of
shutting down the whole process?

kind regards,
Koert
Apr 5 '07 #1
1 1429
Look at this one.

http://www.codeproject.com/csharp/dy...ginmanager.asp

"Koert" wrote:
Hi,

I try to load an assembly, use it and then release it. I am wondering if
there is a way to release the assembly?
I've read that if you use the current AppDomain this is not possible, so you
have to create a second domain to load the assembly, use it and unload the
domain. I use the following code:

//I have an dll called test in the current directory that I want to load
//The assembly is not domain-neutral
string lAssemblyName = Directory.GetCurrentDirectory() + @"\Test.dll";

//Create application domain setup and set the base directory to the current
directory
AppDomainSetup AppDomSetup = new AppDomainSetup();
AppDomSetup.ApplicationBase = Directory.GetCurrentDirectory();

//Create the new domain and load the assembly
AppDomain NewDomain = AppDomain.CreateDomain("SecDomain", null, AppDomSetup);
NewDomain.Load("Test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");

//After using it (not shown here), unload the new domain
AppDomain.Unload(NewDomain);

//Try to copy a dll over the unloaded dll (with overwrite = true);
File.Copy(@"C:\Test1.dll", lAssemblyName, true);
This gives the following exception:
The process cannot access the file '..\Test.dll' because it is being used by
another process.

So the dll is still not released. Is there a way to release it instead of
shutting down the whole process?

kind regards,
Koert
Apr 6 '07 #2

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

Similar topics

3
by: Roy Benjamin | last post by:
I'm developing a WEB service for Sun ONE deployment (AppServer7). I'm developing on Windows XP Pro though will deploy on Solaris, Sun AppServer7 includes a XercesImpl.jar in share/lib. 2 kb...
3
by: TontonJP | last post by:
Hi, I have a standard WinXP Pro/IIS 5.1/ASP 3.0/MS Access setup at home, which I use to develop web apps as a hobby. I'm trying to upload stuff from a html form's file input field and handle...
5
by: alan | last post by:
Hi all, I have a problem on release memory. If I delcare the following pointer to pointer char, how can I free the allocated memory ? let say "myVar = 20" <---actually it is not a constant,...
13
by: Matthew Wieder | last post by:
In my C# application, I have class which has method that opens an XML document, modifies it and saves it out. I run that method for several different XML documents. What I've found is that the...
4
by: mairhtin o'feannag | last post by:
Hello, I have a tablespace striped across three drives, call them 1,2,3, just to be clever. :) I allocated a lot more space (DMS) than I should have, since I didn't know a way to estimate the...
8
by: Sean | last post by:
I have a service that is pulling alot of records from a SQL Server table in a DataSet. This process takes up alot of memory, which is to be expected. But when the process is finished, I am clearing...
4
by: pepcag | last post by:
I used http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconalteringsoapmessageusingsoapextensions.asp as a template to create a very simple web method with soap...
2
by: Oenone | last post by:
I've an ASP.NET 2.0 project into which various Plug-In DLLs can be installed. I'm running it in the ASP.NET Development Server. In order to load one of the PlugIn DLLs I'm using...
2
by: Adam Hartshorne | last post by:
Hi All, I have the following problem. I have just installed visual studio 2003 (v7.1) on a new laptop. I also have the same version installed in a desktop pc. As a test, i tried compiling some...
6
by: S Wheeler | last post by:
I have a REALLY nasty problem and could use some expert help. I have two mixed mode apps. Each uses a mixed mode DLL that exports a couple of classes. There is no dll main as it is not needed....
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.