简体   繁体   English

如何清除.NET的反射缓存?

[英]How can I clear .NET's reflection cache?

If I use reflection to retrieve an assembly, it will seek out the assembly and then cache it. 如果我使用反射来检索程序集,它将查找该程序集,然后对其进行缓存。 I can tell this because, if it fails to find the assembly, it won't find it even after I add it to the correct location. 我之所以这样说是因为,如果找不到装配,即使将其添加到正确的位置也找不到。 If it finds the assembly and I remove it, it still uses the assembly it found and cached. 如果找到了程序集并删除了它,它仍将使用找到并缓存的程序集。

I know I'm not the only one to have this issue: Clear .Net Reflection cache 我知道不是唯一一个出现此问题的人: 清除.Net反射缓存

The code I'm using to get the assembly is the following - and I make this call every time (not caching myself): 我用于获取程序集的代码如下-我每次都进行此调用(而不是缓存自己):

// Try to get the assembly referenced.
Assembly reflectedAssembly;
try
{
    reflectedAssembly = Assembly.Load(assembly);
}
catch (FileNotFoundException)
{
    errorMessage = string.Format("Could not find assembly '{0}'", assembly);
    result = null;
    return false;
}

What I want to know is if there's a way to clear the reflection cache without restarting the process. 我想知道的是,是否有一种方法可以在不重新启动进程的情况下清除反射缓存。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks in advance! 提前致谢!

您无法在.Net中卸载程序集-但是,您可以关闭应用程序域(程序集被加载到其中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM