Accessing Members of Dynamically Loaded Assemblies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordan S.

    Accessing Members of Dynamically Loaded Assemblies

    I plan to load an assembly during application startup, and load that
    assembly via reflection (i.e., it isn't referenced in the application's
    assembly manifest). The assembly will be loaded into the application's
    default app domain, with code like this:

    using System.Reflecti on;
    Assembly loadedAssembly = Assembly.LoadFi le(pathToMyAsse mbly);

    My question: When I need to access members of the assembly [loaded via
    reflection], how does the application know to get the member from the
    dynamically loaded assembly [that is already loaded]? Am I required to get a
    runtime reference to that dynamically loaded assembly? and execute GetType()
    on that assembly reference?
    Or will the Framework attempt to locate the assembly by first looking into
    the current app domain before going to the assembly manifest to try to load
    the assembly?

    I have read up on assembly binding and probing rules and heuristics, but
    what I have read assumes that the assembly is listed in the application's
    assembly manifest... looks there, then goes through the normal probing
    sequence. Is it possible that I've missed something ? and that the "normal
    probing sequence" actually starts with the application's default application
    domain and uses any loaded assembly before searching the GAC, /bin,
    <probinglocatio ns, etc?

    Thanks.



  • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

    #2
    Re: Accessing Members of Dynamically Loaded Assemblies

    Jordan S. wrote:
    I plan to load an assembly during application startup, and load that
    assembly via reflection (i.e., it isn't referenced in the application's
    assembly manifest). The assembly will be loaded into the application's
    default app domain, with code like this:
    >
    using System.Reflecti on;
    Assembly loadedAssembly = Assembly.LoadFi le(pathToMyAsse mbly);
    >
    My question: When I need to access members of the assembly [loaded via
    reflection], how does the application know to get the member from the
    dynamically loaded assembly [that is already loaded]? Am I required to get a
    runtime reference to that dynamically loaded assembly? and execute GetType()
    on that assembly reference?
    If any class you load already has a reference to that assembly then
    there are no need to load it this way.

    If you load it this way you will want to do something like:

    IFoobar o = (IFoobar)loaded Assembly.Create Instance("Fooba rA");

    where IFoobar is an interface the app knows and FoobarA is
    an implementation that the app does not know.

    Arne

    Comment

    Working...