如何避免动态加载已使用反射加载的程序集?

发布于 2024-12-10 19:42:44 字数 141 浏览 3 评论 0原文

我正在循环中使用 Assembly.LoadFile( assemblyFilePath) 加载程序集,并且如果程序集已加载一次,我想避免调用 Assembly.LoadFile 。我是否应该担心对已加载的 DLL 重复调用 Assembly.LoadFile?谢谢。

I am loading assemblies using Assembly.LoadFile(assemblyFilePath) in a loop and I want to avoid calling Assembly.LoadFile if the assembly has already be loaded once. Should I be concerned about calling Assembly.LoadFile repeatedly for a DLL that has already been loaded? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-12-17 19:42:44

不,您不需要担心,因为如果程序集已经加载,它将不会再次加载

如果您调用 Assembly.LoadFile() 那么您可以多次加载相同的程序集,但前提是您从不同的程序集加载每次的路径。您可以使用 程序集。 Load() 只会加载一次程序集。您还可以使用以下命令找到当前应用程序域中已加载的程序集

Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();

No you don't need to be concerned because if an assembly has already been loaded it won't be loaded again

If you call Assembly.LoadFile() then you can load the same assembly multiple times but only if you are loading assembly from different path each time. You can use Assembly.Load() which will load an assembly only once. You can also find about already loaded assemblies in current app domain using

Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
很糊涂小朋友 2024-12-17 19:42:44

对于给定的 AppDomain,您可以调用 GetAssemblies 并查看它是否已加载。

For the given AppDomain, you can call GetAssemblies and see if it's loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文