本文介绍了是Assembly.LoadFrom保持开放的文件句柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用
Assembly.LoadFrom("path.exe");
之后,我似乎无法删除的文件系统EXE。所以我在想,如果这条道路保持一个开放的文件句柄和我怎么能收呢?
and after that i cant seem to delete that exe from the file system. so i was wondering if this path keeps an open file handle and how i can close it?
推荐答案是的,它是开放的,直到该组件是从应用程序域卸载。
Yes, it is open until the assembly is unloaded from the appdomain.
如果您真的需要删除的文件,其内容加载到内存中。使用 的Assembly.Load(字节[]) 加载程序集:使用
If you really need to delete the file, load its content into memory. The use Assembly.Load(byte[]) to load the assembly:
using (Stream stream = File.OpenRead("path.exe")) { byte[] rawAssembly = new byte[stream.Length]; stream.Read(rawAssembly, 0, (int)stream.Length); Assembly.Load(rawAssembly); }更多推荐
是Assembly.LoadFrom保持开放的文件句柄?
发布评论