开发者

release Assembly.LoadFrom file handle

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜