When does the CLR load an assembly in a .NET process?

倖福魔咒の 提交于 2019-12-07 08:44:30

问题


  1. Is a .NET assembly loaded by the CLR when a class from the assembly is referenced?

Or

  1. When a class which declares the using namespace from the assembly is loaded?

Also having loaded an assembly, does it ever unloads the assembly if it is not used for a long time?


回答1:


It's the JIT compiler that instructs the CLR to load an assembly once it has translated it to machine code which is done on demand and the exact time is not deterministic. As to the second question, once an assembly is loaded into the AppDomain, the only way to unload it is to destroy this AppDomain, there's no other way to unload an assembly.




回答2:


It is loaded when you attempt to use a type from the assembly. When the program gets to executing a type that it doesn't know about it, the runtime goes and resolves the type, which then loads the assembly that contains that type.




回答3:


Assemblies are loaded in various ways (Project references, direct references--both of these during compile-time (OK, apparently not)), but not by Using statements. They are to my knowledge never unloaded again.



来源:https://stackoverflow.com/questions/2631341/when-does-the-clr-load-an-assembly-in-a-net-process

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