473,769 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Jun 27 '08 #1
1 1378
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
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2995
by: lanky_tx | last post by:
Hi All, We have an automated build and test environment using NAnt and Nunit. Some of our assemblies are being strong named by modifying the AssemblyInfo.cs and having csc compile it. Some of these strong named assemblies are being dynamically loaded into the runtime. We store the metadata information about the strong named assemblies in a config file. Metadata in the config file looks like this:
6
9769
by: Jimmy | last post by:
Hi, Sorry for the complete newb question, but none of the 3 books I own on C# cover this. If I place say, 10 or 15 functions in a codefile, what's the best method to call these functions from say Form1.cs ? thanks for all the help, I'm really trying here.
1
1953
by: Robert Vasquez | last post by:
I would like my application to be able to load modules dynamically and release them once they aren't needed. For example in c++ I would load a dll containing the required function, run it, then release the dll after it's no longer needed. What are my options in c#? From what I have read so far I can load assemblies containing the required code to execute but I can't release it without releasing the main application domain that loaded it. Is...
0
1328
by: Verane | last post by:
Hi all, I am working with C# and Visual studio 2003. What I want to do is the following : I have 3 assemblies, let call them A.exe, B.dll and C.dll. I want to dynamically load B and C when A is loaded. B and C are statically referencing A. Those three projects are in the same solution called mySolution.
6
2814
by: mflanagan | last post by:
I have unmanaged C++ program that will load a managed C++ dll and then call a function in that dll. The managed C++ routine will call some C# routines. The unmanaged C++ main program will make these calls (to the managed C++ dll) many times, from many different threads. Each thread will do a LoadLibrary, call one C++ routine in the managed dll, and upon return, unload the library and exit. I'm concerned about class variables (static)...
2
1683
by: brian.gabriel | last post by:
I have a core web service that acts as a gateway for several third party web services. Each one of the third party web services has it's own "interface" class derived from a main interface. When the main web service receives a request it will load the appropriate class with Activator.CreateInstance. Currenty all classes are compiled into a monolithic assembly. I want to be able to move each "interface" to its own assembly. The end...
1
1918
by: dnn | last post by:
How can I access dynamically loaded variables? I am trying to load an external javascript file dynamically and then access its variables. The script is loaded by the onload handler. The code looks like this: var constants = document.createElement("script"); constants.src = REL_PATH + "extensions_demo/js/constants_" + MY_LANGUAGE + ".js"; constants.type ="text/javascript";
2
3119
by: Smithers | last post by:
Using 3.5, I am stuck in attempting to: 1. Dynamically load an assembly 2. Instantiate a class from that assembly (the client code is in a different namespace than the namespace of the dynamically loaded assembly) so far so good (per my code below)... but here is where I'm getting hung up: 3. Call methods of that type (see comments in my code) If the types in the dynamically loaded assembly were in the same namespace
2
5114
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.