Assembly.LoadFrom加载程序集无法释放资源的解决方案

本文介绍了一种解决程序运行中DLL文件被占用的方法,通过将DLL文件读取到内存中再加载,避免了DLL文件被外部操作导致的问题。但该方法不自动加载关联程序集。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面此方法加载程序集会导致程序集一直被占用

Assembly asm = Assembly.LoadFrom(dllPath);

解决方案:

//通过此方法读取可以解决dll被占用问题
byte[] fileData = File.ReadAllBytes(dllPath);
Assembly asm = Assembly.Load(fileData);

 但此方法不会自动加载关联的程序集,暂未找到解决方案

转载于:https://www.cnblogs.com/feigao/p/8872846.html

有关调用实时(JIT)调试而不是此对话框的详细信息, 请参见此消息的结尾。 ************** 异常文本 ************** System.OutOfMemoryException: 内存不足。 在 System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) 在 System.Drawing.Image.FromFile(String filename) 在 PDFConvert.WinForm.frmMainInfo.frmMainInfo_Load(Object sender, EventArgs e) 在 System.Windows.Forms.Form.OnLoad(EventArgs e) 在 System.Windows.Forms.Form.OnCreateControl() 在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl() 在 System.Windows.Forms.Control.WmShowWindow(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m) 在 System.Windows.Forms.ContainerControl.WndProc(Message& m) 在 System.Windows.Forms.Form.WmShowWindow(Message& m) 在 System.Windows.Forms.Form.WndProc(Message& m) 在 PDFConvert.bllSkinForm.SkinWin7.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) ************** 已加载程序集 ************** mscorlib 程序集版本:4.0.0.0 Win32 版本:4.8.9290.0 built by: NET481REL1LAST_C 基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll ---------------------------------------- SmallPDF 程序集版本:6.8.0.0 Win32 版本:6.8.0.0 基本代码:file:///E:/%E2%98%85%E2%98%85%E8%BD%AF%E4%BB%B6%E4%BD%BF%E7%94%A8%E4%B8%AD/%E8%BF%85%E6%8D%B7PDF%E8%BD%AC%E6%8D%A2%E5%99%A8/SmallPDF%206.8.0/SmallPDFer/SmallPDFer.exe ---------------------------------------- System.Windows.Forms 程序集版本:4.0.0.0 Win32 版本:4.8.9256.0 built by: NET481REL1LAST_B 基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- PDFConvert.bllBase 程
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值