unload a loaded assembly

  • Thread starter Dominique Vandensteen
  • Start date
D

Dominique Vandensteen

I want to make a program that checks for updates at start...
The way I am doing this is to create 2 projects...

A simple exe checks the server for the version and downloads a dll if
needed.
The dll contains the program itself (so simple a form out of that dll is
started).

My problem is that the exe loads the dll ([Assembly].LoadFrom(..)) and gets
the version of that assembly to find out if an update is needed.
If an update is needed, I need to unload that assembly to be able to
overwrite the previously loaded dll.

Anybody an idea how to do this?


Dominique
 
H

Herfried K. Wagner [MVP]

* "Dominique Vandensteen said:
A simple exe checks the server for the version and downloads a dll if
needed.
The dll contains the program itself (so simple a form out of that dll is
started).

My problem is that the exe loads the dll ([Assembly].LoadFrom(..)) and gets
the version of that assembly to find out if an update is needed.
If an update is needed, I need to unload that assembly to be able to
overwrite the previously loaded dll.

Load the assembly into a separate appdomain and unload the appdomain.
 
D

Dominique Vandensteen

still can't delete the file...
am I doing something wrong?

my code:

dim filename as String = "c:\myfile.dll"
dim filebyte() as Byte = LoadFile(filename)

Dim versionDomain As AppDomain =
AppDomain.CreateDomain("DummyToCheckVersion")
Dim a As [Assembly] = versionDomain.Load(filebytes)
Dim version As Version = a.GetName.Version
AppDomain.Unload(versionDomain)

File.Delete(filename)


the delete fails:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred
in mscorlib.dll
Additional information: Access to the path "c:\myfile.dll" is denied.




Herfried K. Wagner said:
* "Dominique Vandensteen said:
A simple exe checks the server for the version and downloads a dll if
needed.
The dll contains the program itself (so simple a form out of that dll is
started).

My problem is that the exe loads the dll ([Assembly].LoadFrom(..)) and gets
the version of that assembly to find out if an update is needed.
If an update is needed, I need to unload that assembly to be able to
overwrite the previously loaded dll.

Load the assembly into a separate appdomain and unload the appdomain.
 

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