Reflection will not allow Delete

  • Thread starter Thread starter nzpcmad
  • Start date Start date
N

nzpcmad

I have a C# .NET application that automatically updates software. It
downloads an update if available, gets the version numbers of the
downloaded and current files, displays these and if the user is happy,
deletes the current file and copies the downloaded one.

I get the version number of the current file via:

Version assOldVer = System.Reflection.Assembly.LoadFrom(applicationFileName).GetName().Version;

However, when I try and delete via

File.Delete (applicationFileName);

I get an error. It seems that the files is in use?

I can't find any "Close" method for the Reflection method.

Any ideas?

Many thanks
 
I don't have a link to the solution but it is as follows (not exactly but I
hope you get the idea).

First load the assembly into a byte array. Then use the LoadFrom which
takes a byte array. This way reflection does not lock the file which is
what you are seeing.

Lloyd Sheen
 
Thanks for this. I couldn't find a way to load the assembly into a
byte array. You can load a byte array into an assembly. Also, wouldn't
loading the assembly (in whatever way) still leave the file "in use"?

I copied the file and then loaded the copy - which fixed my problem.

Thanks
 
Back
Top