清除 .Net 反射缓存 [英] Clear .Net Reflection cache

查看:38
本文介绍了清除 .Net 反射缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在动态编译C#源代码时,如果我们碰巧尝试执行一个缺少引用的已编译目标DLL(例如tmp901.tmp.dll),例如:

When doing dynamic compiling of C# source code, if we happen to try to execute a compiled target DLL (for example tmp901.tmp.dll) that has a missing reference, for example:

InnerException:无法加载文件或程序集_O2_Scanner_MsCatNet,版本=1.0.0.0,Culture=neutral,PublicKeyToken=null"或其依赖项之一.

似乎存在一个问题,在该过程中,该程序集永远不会得到解决,即使文件被复制到执行目标程序集 (tmp901.tmp.dll) 的位置也是如此.似乎存在缓存问题,导致无法重新检查 dll 是否存在.

There seems to be an issue where, for the duration of that process, that assembly will never be resolved, even if the file is copied to the location where the target assembly (tmp901.tmp.dll) is being executed from. There seems to be a caching issue going on that prevents the recheck for the dll existence.

目前的解决方案是重新启动主机 .NET 应用程序,这并不实用.

The current solution is to restart the host .NET app which is not really practical.

推荐答案

一旦程序集加载失败,我相信您仍然可以使用 Assembly.LoadAssembly.LoadFile.这应该允许您强制加载程序集,即使它失败了一次.

Once the assembly load fails, I believe you can still load the assembly manually using Assembly.Load or Assembly.LoadFile. This should allow you to force the assembly to load, even if it's failed once.

这篇关于清除 .Net 反射缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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