删除临时dll时获取UnAuthorizedAccessException [英] Getting UnAuthorizedAccessException while deleting a temp dll

查看:73
本文介绍了删除临时dll时获取UnAuthorizedAccessException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在运行时创建一个dll,最终在使用该dll之后,我试图在运行时删除该dll,但我遇到了UnAuthorizedAccessException.
File.Delete(位置).

但是一旦关闭应用程序后,如果我尝试在加载应用程序时删除该文件,则该dll仅在运行时被删除.

任何人都可以告诉解决方案.

问候,
Ramana

Hi,
I''m creating a dll at run time and after using that dll finally I''m trying to delete that dll at run time but I''m getting UnAuthorizedAccessException .
File.Delete(location).

But once after the application is closed and if I try to delete that file while the application is loaded then that dll is getting deleted at run time only.

Can anyone please tell the solution.

Regards,
Ramana

推荐答案

好吧,由于您的应用程序仍在引用dll,因此可能会发生异常.因此,一旦使用完引用的dll,在调用File.Delete("dllPath")方法之前先将其卸载.请参见此处如何卸载程序集.
http://msdn.microsoft.com/en-us/library/c5b8a8f9 (v = vs.80).aspx [
Well, the exception might be occured due to your application still referencing the dll. So once you finished using the referenced dll, unload it before calling the File.Delete("dllPath") method.See here how to unload an assembly.
http://msdn.microsoft.com/en-us/library/c5b8a8f9(v=vs.80).aspx[^]

I hope this helps you well.


一旦将.DLL加载到进程中,即使在您不再使用.DLL的情况下,该文件也会在该进程的生命周期内被锁定. DLL的代码.

您必须将.DLL加载到单独的AppDomain中,才能开始使其工作.当您完成.DLL的工作后,便销毁了已加载到其中的AppDomain,并且文件锁消失了.当然,这并不完全那么简单,但这是您要做的基本框架.
Once a .DLL is loaded into a process, the file is locked for the lifetime of that process, even if you''re no longer using the .DLL''s code.

You''ll have to load the .DLL into a seperate AppDomain in order to begin to get this to work. When you''re done with the .DLL, you destroy the AppDomain it''s loaded into and the file lock goes away. Of course, it''s not entirely that simple, but that''s the basic framework of what you have to do.


这篇关于删除临时dll时获取UnAuthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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