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

时间:2012-03-06 21:46:10

标签: c# .net caching reflection

如果我使用反射来检索程序集,它将查找程序集然后缓存它。我可以告诉它,因为,如果它找不到程序集,即使我将它添加到正确的位置后也找不到它。如果它找到了程序集并将其删除,它仍然使用它找到并缓存的程序集。

我知道我不是唯一有这个问题的人:Clear .Net Reflection cache

我用来获取程序集的代码如下 - 我每次都打这个电话(不是自己缓存):

// 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;
}

我想知道的是,如果有办法清除反射缓存而不重新启动进程。任何帮助将不胜感激。

提前致谢!

1 个答案:

答案 0 :(得分:4)

您无法在.Net中卸载程序集 - 但您可以关闭应用程序域(加载程序集的位置)。

相关问题