NET search path use Assembly.LoadFrom() but even in that case, check using AppDomain.GetAssemblies() method if the assembly is already loaded before into the AppDomain.įor a long time, I was confused as to why. So to get an assembly loaded 10 times, you need to have 10 different locations where the same assembly is present.Īs a thumb rule, you should always rely on Assembly.Load in case you know the path of assembly is not in. No no, don't think it is that lazy if you give this method same location again it will not load the assembly again from same path but it will do if path is different.
If you call this method, it will load the assembly every time in the AppDomain. It tries to minimise its work and does not look for anything. This is the most lazy method you can say. So, using the above two methods, you can load an assembly at least two times even if everything in those assemblies is the same. In short, Assembly.LoadFrom allows assembly to be loaded once from a path from which it has not been loaded yet. but after that, if I try to load assembly from path 3 using Assembly.LoadFrom, it will not be loaded now as it has already been loaded from path 2. but if I do so using path 2, the assembly will be loaded again. Now if I try to load the assembly using Assembly.LoadFrom from path 1, it will not be loaded. When the application will run, this assembly will automatically be loaded from the first path. At path C:\MyApplication\ExternalAssemblies.Application output path, say C:\MyApplication\bin\Debug.The beauty of this is that it does not load same assembly again from any other path if it has been loaded by this method before.įor example, let's say I have MyAssembly.dll at the following path:
Assembly.LoadFrom()Īssembly.LoadFrom takes the full path of the assembly and if you call this method, it will load assembly into the application domain provided it has not been loaded from the same path by this or any of the other methods. Using this method, you can load assembly of a single version only once.
You can find more details here regarding How Runtime Locates Assemblies. NET defined algorithm to search for an assembly. Assembly.Load()Īssembly.load takes the fully qualified assembly name and uses the. Let me first explain what all Assembly.Load****() method does before I start answering the questions. I hope some of you may find these questions silly and some may be thinking how does that matter. Can I have n copies of an identical assembly loaded in an application domain? How will the system behave in that case?
This gave me an opportunity to learn about two well known methods of Assembly Loading Assembly.Load(), Assembly.LoadFrom() and one less known method Assembly.LoadFile(). NET, I came across various scenarios in which I had to manually load assemblies into my application.