Version of an assembly

  • Thread starter Thread starter Roberto M. Oliva
  • Start date Start date
R

Roberto M. Oliva

hello all!

I am trying to do an update service for the executable of my application. I
download the new file and compare the versions of both assemblies using the
next code:

Dim new_assembly As System.Reflection.Assembly

Dim old_assembly As System.Reflection.Assembly

Dim new_build As Integer

Dim old_build As Integer

new_assembly = System.Reflection.Assembly.LoadFrom(strPathNew)

old_assembly = System.Reflection.Assembly.LoadFrom(strPathOld)

new_build = new_assembly.GetName().Version.Build

old_build = old_assembly.GetName().Version.Build

new_assembly = Nothing

old_assembly = Nothing

If (new_build > old_build) Then

' Delete the old one... and update to the new

System.IO.File.Delete(strPathOld)

System.IO.File.Move(strPathNew, strPathOld)

Else

' Delete the new one... the old remain

System.IO.File.Delete(strPathNew)

End If


strPathNew points to the recently downloaded executable and strPathOld
points to what was previously on the PDA.
Either I do a Move or a Delete I get an UnauthorizedAccessException error.

If I don't test the version of the assembly (I update to the new file
directly without testing versions, for example) everything works fine... so
I suspect there is something to do with the Assembly.LoadForm. But the file
remains loaded beyond the new_assembly = Nothing...

Can anybody tell me something? Any workaround?
Thanks a lot
Roberto
 
The assembly.LoadFrom loads the assembly into memory
which locks it. Once locked you can't move it, etc.

On the desktop you would solve this by creating a new
appdomain and loading hte assembly in that appdomain.
Then unload the appdomain which unloads the assembly and
you are all set.

The problem is that you can't unload an assembly without
unloading the appdomain that it was loaded into.

Another option might be to check the file version instead
of the internal assembly version. The two typically
map...

-----Original Message-----

hello all!

I am trying to do an update service for the executable of my application. I
download the new file and compare the versions of both assemblies using the
next code:

Dim new_assembly As System.Reflection.Assembly

Dim old_assembly As System.Reflection.Assembly

Dim new_build As Integer

Dim old_build As Integer

new_assembly = System.Reflection.Assembly.LoadFrom (strPathNew)

old_assembly = System.Reflection.Assembly.LoadFrom (strPathOld)

new_build = new_assembly.GetName().Version.Build

old_build = old_assembly.GetName().Version.Build

new_assembly = Nothing

old_assembly = Nothing

If (new_build > old_build) Then

' Delete the old one... and update to the new

System.IO.File.Delete(strPathOld)

System.IO.File.Move(strPathNew, strPathOld)

Else

' Delete the new one... the old remain

System.IO.File.Delete(strPathNew)

End If


strPathNew points to the recently downloaded executable and strPathOld
points to what was previously on the PDA.
Either I do a Move or a Delete I get an
UnauthorizedAccessException error.
If I don't test the version of the assembly (I update to the new file
directly without testing versions, for example) everything works fine... so
I suspect there is something to do with the
Assembly.LoadForm. But the file
 
Back
Top