I am curious to know what the disadvantage is by calling Assembly.Load(AssemblyName)
numerous times with the same version of assembly. Does the runtime know not to load the assembly again after the first call? If not, is there any way to detect what's already loaded?
Thanks in advance.
When you use this overload it will be loaded only once in memory. You can verify it with Process Explorer. Look at the loaded modules list. Every assembly is loaded up to .NET 3.5 with LoadLibrary. Additionally it is loaded as memory mapped file into the process.
Starting with .NET 4.0 an assembly is loaded only as memory mapped file and not via LoadLibrary anymore except if it is a precompiled ngenned assembly.
This breaking change in .NET 4 was done because MS found during the development of VS 2010 that their memory did deplete rather quickly. Somebody found that every loaded assembly cosumed twice its original size in virtual memory because it was loaded once via LoadLibrary and a second time as memory mapped file. This is not easy to find except if you look with VMMap into your process. Due to the massive amount of code in VS this was a major issue for VS2010 which is now mostly managed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With