Use. .NET to get the loaded assembly is incomplete, although we refer to other libraries, but without calling, it cannot be obtained in the loaded assembly, this article shares to get the complete assembly assembly in WinForm and ASP.NET.
introduction
Use. .NET to get the loaded assembly is incomplete, although we refer to other libraries, but without calling, it cannot be obtained in the loaded assembly, this article shares to get the complete assembly assembly in WinForm and ASP.NET.
ASP.NET (unmeasured)
The .NET Framework defers loading assemblies into the current AppDomain until they are needed. For example, if you only call a third-party library from SomeMethod(), the third-party DLL will usually not be loaded until the first run of SomeMethod().
AppDomain.GetAssemblies() gives you all the assemblies that have been loaded into the current AppDomain. BuildManager.GetReferencedAssemblies() returns a list of all assemblies referenced from Web.config and other locations, and loads those assemblies into the current AppDomain.
Code:
WinForm
Start by using the code below to get the loaded assembly.
The number of Assembly assemblies obtained is 12, as shown in the following figure:
When we don't call the methods of other libraries, the main application does not load its dlls, probably to save performance overhead, so the first time we call the methods of other libraries, it may be a little slower.
Use the modified code, as follows:
The number of assembly assemblies obtained is 117, and the principle is to get the dll under the application directory and load it.
In this case, when calling AppDomain.CurrentDomain.GetAssemblies(). ToList() method, you can get the complete assembly, which may be more than 117.
Get the current assembly
|