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?
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.
This issue was dealt with here
How to unload an assembly from the primary appdomain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With