Clear .Net Reflection cache

孤者浪人 提交于 2019-12-24 08:23:42

问题


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: Could not load file or assembly '_O2_Scanner_MsCatNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/2274310/clear-net-reflection-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!