是Assembly.LoadFrom保持开放的文件句柄? [英] Is Assembly.LoadFrom keeping an open file handle?

查看:175
本文介绍了是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保持开放的文件句柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆