tags:

views:

64

answers:

2

Hi,

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?

+1  A: 

This issue was dealt with here

How to unload an assembly from the primary appdomain

Philip Smith
A: 

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.

Quartermeister