Answered by:
Differences between Assembly.Load() and Assembly.LoadFrom() and related concept (Load context or LoadFrom context) in CLR4

Question
-
I know similar question has been posted. But i'm asking this question specific to CLR4.
I read several related articles, it seems they behave differenently in difference CLR version (Maybe i'm wrong)
Here are the questions:
Q1. If i try to load a target assembly which is under the probing path with Assembly.Load(), this target assembly will be loaded in Load context, but will all the dependencies of this target assembly be loaded into Load context at the same time? if so what happens if some of the dependencies are not under probing path?
Q2. If i try to load a target assembly which is under the probing path with Assembly.LoadFrom(), which context this target assembly will be loaded into? Load context or LoadFrom context?
Q3. If one assembly trys to load a target assembly which is not under the probing path with Assembly.LoadFrom(), this target assembly will be loaded in LoadFrom context, but will all the dependencies of this target assembly be loaded into LoadFrom context at the same time? if so what happens if some of the dependencies are not under same path and not under probing path? And will those dependencies be loaded into Load context that is under probing path?
Q4. If a same identity assembly has been loaded into Load context with Assembly.Load(), what happens if i trys to load a same identity assembly with Assembly.LoadFrom() with a path that is under probing path? and what happens if i trys to load a same identity assembly with Assembly.LoadFrom() with a path that is not under probing path?
Q5. If a same identity assembly has been loaded into LoadFrom context with Assembly.LoadFrom() with a path not under probing path, what happens if i trys to load a same identity assembly that is under probing path into Load context with Assembly.Load()?
I came up with these question after i read some realed MSDN article.
Thanks in advance.
Wednesday, April 11, 2012 2:44 AM
Answers
-
Wednesday, April 11, 2012 2:08 PM
-
Q1 - If the dependencies are not on probing path, then you have to load them via AssemblyResolve event and it depends what you use - LoadFrom/LoadFile.
Q2 - Load context
Q3 - Dependencies under probing path will be in Load context (that's always true). For dependencies from other subdirs you have to use AssemblyResolve event.
Q4 - Load context always wins based on identities (and LoadFrom context will first look in Load context). You cannot load the same identity twice into Load or LoadFrom contexts.
Q5 - LoadFrom will first scan the probing path for the identity, so it will immediatelly load the 'other' assembly under probing path into Load context. Nothing will be loaded into LoadFrom context.
-Karel
- Proposed as answer by Karel ZikmundMicrosoft employee Wednesday, April 11, 2012 2:25 PM
- Marked as answer by Mike Feng Saturday, April 21, 2012 7:24 AM
Wednesday, April 11, 2012 2:25 PM -
Hello,
Follow the threads below to get the clear idea on this.
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3bdaf65c-520c-4a1a-a825-fc2ca2957bf3/
http://blogs.msdn.com/b/junfeng/archive/2005/07/01/434580.aspx (already mentioned above)
- Edited by Karel ZikmundMicrosoft employee Thursday, April 12, 2012 4:55 PM Link the links
- Marked as answer by Mike Feng Saturday, April 21, 2012 7:24 AM
Thursday, April 12, 2012 10:13 AM
All replies
-
Wednesday, April 11, 2012 2:08 PM
-
Q1 - If the dependencies are not on probing path, then you have to load them via AssemblyResolve event and it depends what you use - LoadFrom/LoadFile.
Q2 - Load context
Q3 - Dependencies under probing path will be in Load context (that's always true). For dependencies from other subdirs you have to use AssemblyResolve event.
Q4 - Load context always wins based on identities (and LoadFrom context will first look in Load context). You cannot load the same identity twice into Load or LoadFrom contexts.
Q5 - LoadFrom will first scan the probing path for the identity, so it will immediatelly load the 'other' assembly under probing path into Load context. Nothing will be loaded into LoadFrom context.
-Karel
- Proposed as answer by Karel ZikmundMicrosoft employee Wednesday, April 11, 2012 2:25 PM
- Marked as answer by Mike Feng Saturday, April 21, 2012 7:24 AM
Wednesday, April 11, 2012 2:25 PM -
Hello,
Follow the threads below to get the clear idea on this.
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3bdaf65c-520c-4a1a-a825-fc2ca2957bf3/
http://blogs.msdn.com/b/junfeng/archive/2005/07/01/434580.aspx (already mentioned above)
- Edited by Karel ZikmundMicrosoft employee Thursday, April 12, 2012 4:55 PM Link the links
- Marked as answer by Mike Feng Saturday, April 21, 2012 7:24 AM
Thursday, April 12, 2012 10:13 AM