如何避免动态加载已使用反射加载的程序集?
我正在循环中使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您不需要担心,因为如果程序集已经加载,它将不会再次加载
如果您调用 Assembly.LoadFile() 那么您可以多次加载相同的程序集,但前提是您从不同的程序集加载每次的路径。您可以使用 程序集。 Load() 只会加载一次程序集。您还可以使用以下命令找到当前应用程序域中已加载的程序集
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
对于给定的 AppDomain,您可以调用
GetAssemblies
并查看它是否已加载。For the given AppDomain, you can call
GetAssemblies
and see if it's loaded.