Delete / replace a dll that is in use

P

Patrick B

Problem: how can I programmatically delete a dll that is being used by
my application? I want to programmatically replace the dll with a newer
version.

I have a c# AppUpdater type application. When run, it opens an Access
DB, then checks my website for updates to the DB. If it finds an update
it downloads it. The next time the c# application is run, the newer
version of the Access DB is used. This works great. My problem is that
occassionally the c# application itself must be updated.

What I've done is separated all the important code into a dll. My app
can check the version of the dll, check my website for a newer version,
and if there is a newer version, it can download it. The problem is that
Windows won't let the new dll be installed over the current dll.

Any suggestions?

Thanks in advance,

-Patrick
 
V

Vijaye Raji

Yes. You cannot replace a dll that's being used. What you want to do is
load your dlls dynamically, so, when they need updating, you unload them and
replace them and load them again.

Another option is to have the updater as a separate executable that your
main program will launch and quit. The updater, after downloading the new
version of the dll will launch your main program again.

-vJ
 
C

Cor Ligthert

Patrick,

This is a normal problem and by everybody handled in my opinion in the same
way.
To update your programs you need a seperated update program.

Which test if your program is active and than show the messages as you have
seen by others.

The in my opinion most simplest snippet to test, however it shows as well
programs running with the same name what is in this case in my idea no
problem.
\\\
bool mutCreated;
System.Threading.Mutex mut
= new System.Threading.Mutex(true, "myProgram", out mutCreated);
if (!mutCreated) MessageBox.Show("There is already a X running please
close this");
///

Than download the program with another name and rename or delete the old one
when succeeded and rename the downloaded to the needed name.

When you have to update the update program, than you are forced to first to
download the updater, start the downloaded one and close the old, than
delete the old one and going on..

Just some idea's

Cor
 
C

Chris Rolon

You will need to take down your application and restart it. That is how the
AppUpdater block works. There is a shim app that is responsible for doing
the downloads and offering the user the ability to update to the new
version.

Except by loading the dll in an AppDomain, .Net does not provide a method of
unloading the dll from memory. If you use an AppDomain, you can unload it,
along with the dlls that are loaded into it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top