473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How load a DLL dynamically

I am working in VB 2005. I want to be able to load a DLL selected dynamically from a list.

I have had advice and this is where I am so far:

************************************************** ************
thisAssemblyObject = System.Reflection.Assembly.GetEntryAssembly()

returnValue = thisAssemblyObject.CreateInstance("DeviceComms.Dev iceComms" ...)
************************************************** ************

Whatever I have tried in the second line has not worked and I am at a loss to know what to try.

Brenton
Nov 10 '08 #1
2 1152
PRR
750 Expert 512MB
firstly you need to get all the Types of the current assembly... loop through it n then create a object..have a look at this ...
Expand|Select|Wrap|Line Numbers
  1. try
  2.             {
  3.                 Assembly myass = Assembly.GetEntryAssembly();//GetExecutingAssembly();
  4.  
  5.                 Type[] t = myass.GetTypes();
  6.  
  7.                 foreach (Type tt in t)
  8.                 {
  9.                     Console.WriteLine(tt.FullName.ToString());
  10.  
  11.                     if (tt.FullName.ToString() == "ConsoleApplication2.Program")//class namespace+classname
  12.                     {
  13.                         object o = Activator.CreateInstance(tt);
  14.  
  15.                         if (o != null)
  16.                         {
  17.                             MethodInfo m = o.GetType().GetMethod("my");
  18.  
  19.                             m.Invoke(o, null);
  20.                         }
  21.                     }
  22.                 }
  23.  
  24.  
  25.             }
  26.             catch (Exception eee)
  27.             {
  28.                 Console.WriteLine(eee.Message.ToString());
  29.             }
  30.  
Nov 10 '08 #2
Plater
7,872 Expert 4TB
I have just been researching this myself.

I happen to have a DLL that I use as a webserver, and I wish to load it dynamically in my program:
Expand|Select|Wrap|Line Numbers
  1. //
  2. //
  3.  
  4. Assembly asm = Assembly.LoadFrom("myHttpListener.dll");
  5. object o;//this will become the instance of my class
  6. //the constructor takes 1 argument, an integer that defines the port to listen for connections on
  7. object[] myparams = new object[]{8090};
  8. //create an instance of "Plater.HttpListener", not case sensitive, default bindingflags and myparams contains the arguments passed to constructor
  9. o = asm.CreateInstance("Plater.HttpListener", true, BindingFlags.Default, null, myparams, null, null);
  10. //Now, by using the Type, I will invoke my "Start" function in my class
  11. //Note that I provided the object instance of my class "o" as the object to invoke the function on
  12. o.GetType().InvokeMember("Start", myflags | BindingFlags.InvokeMethod, null, o, null);
  13.  
  14. //
  15. //
  16.  
Nov 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ron Vecchi | last post by:
I am using the FlashShockWave COM object. in the form design mode I specified the Flash Movie .SWF local path. and it loads correctly. My problem is that if I make changes to the swf file it...
1
by: TIM T | last post by:
I want to load a user control from a dll dynamically to my main form. I have been reading about using reflection. I got this to work with the methods from my other classes in the dll but I am not...
3
by: Boni | last post by:
Dear Sirs, If I dynamically load assembly into the memory by Load(byte) how long do I have to preserve the array valid? Can it be destructed just after the load call? Thanks in advance, Boni
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
6
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
1
by: chandu | last post by:
hello , i want to load and execute an existing dll in a applicaiton dynamically with out giving references etc... need to create separate appdomain or in same appdomain can i load and execute...
2
by: Nick | last post by:
I have two navigation user controls and based on a query string will load one or the other. On the page that will load the user control I cannot do the following Dim uc As FlashNavigation (The...
7
by: kendu | last post by:
Is it possible to dynamically load a form from file? This form is just a .vb file and has not been added to the project during design time. Ken
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.