Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

release Assembly.LoadFrom file handle

Tags:

c#

.net

file

I'm trying to get assembly version of an exe in C# with the following code

Assembly asm = Assembly.LoadFrom(address);
return asm.GetName().Version;

it works perfect but if I try to delete the exe after I used this function, it says "Access Denied" since the exe is being used by another process!

is there any Dispose call or something which releases the file handle or any other solution?

like image 663
MBZ Avatar asked Jul 19 '10 13:07

MBZ


2 Answers

There is no way to unload an assembly other than unloading the application domain. See How to: Load and Unload Assemblies:

There is no way to unload an individual assembly without unloading all of the application domains that contain it. Use the Unload method from AppDomain to unload the application domains. For more information, see Unloading an Application Domain.

If you just want to get the version of a file, try using FileVersionInfo.GetVersionInfo.

like image 180
Quartermeister Avatar answered Oct 11 '22 15:10

Quartermeister


This issue was dealt with here

How to unload an assembly from the primary appdomain

like image 21
Philip Smith Avatar answered Oct 11 '22 17:10

Philip Smith