473,387 Members | 1,799 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,387 software developers and data experts.

Loading an assembly on the fly with params in constructor

I am trying some interresting features to load an assembly on the fly.
I read some samples, but what I am trying to do is a little more
complex.

- First, I have a app.config file containing keys like
"mydll_MyClass.dll"
- Second, I tried to load the assembly with Assembly.LoadFrom(myDll),
but since my constructor having some parameters this is not
possible.
- Third, I tried Activator.CreateInstance(...), but it becomes very
confusing to manage Types ... the examples I have seen use
Type.GetConstructor that I don't know how to use... To access this
function, I have to do Type.GetType(myDll).GetConstructor ( with type
here in params... don't know what type this time!!!)

So I tried the following code

// Getting the assembly to load... my own function, don't pay
attention
// here... the result put "mydll_MyClass.dll" in the string
assemblyList[0]
appConfig = new AppConfig.Config(ConfigurationSettings.AppSettings );
assemblyList = appConfig.GetAssemblyList();
System.Console.WriteLine("The assembly list: " + assemblyList[0]);
Assembly assembly = Assembly.LoadFrom(myPath + assemblyList[0]);
Type assemblyType = assembly.GetType(assemblyList[0]);

// The constructor name MyClass, that I want to someday extract from
// the name of mydll_MyClass.dll, but hardcoded here
// Here is the PROBLEM!, it returns null exception when finding
// constructor.
MethodInfo constructor =
assemblyType.GetMethod("MyClass");

Object obj = Activator.CreateInstance(assemblyType);
Object[] args = new Object[1];
// add a reference as target for the assembly to load and display
// my stuff, this is the param of my constructor
args[0] = this.Controls;
constructor.Invoke(obj, args);
Finally, if you have another solution I am open... :) My goal is to
have many .dll not referenced to my project, but load them via the
information that I can store in app.config file, and with params in
constructor of my assemblies class.

Thanks

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #1
0 1386

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

Similar topics

2
by: Foehammer | last post by:
Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names. TestLib is the dll where all the...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the...
4
by: Phil Da Lick! | last post by:
Hello, Got strings.resx included in my assmebly as the default language neutral collection. ResourceManager res=new ResourceManager("strings", Assembly.GetExecutingAssembly()); string...
3
by: dhnriverside | last post by:
Hi guys I'm writing a console app in C# for which i want to enable the user to have several "plug-ins". The app has a switch to set the plug-in to use, and at runtime the required dll is loaded...
0
by: Fred | last post by:
Hello, I am using a separate app domain to load an assembly from either disk or cache, create an instance of it and run a method. I then call dispose on the created instance and unload the app...
4
by: hyd | last post by:
With C++/CLI - VS2005, is it possible to have static constructors that are automatically called when the owner assembly is loading ? Otherwise, how it is possible to call it without creating an...
7
by: Frank | last post by:
I'm running into trouble and I hope someone can help. I have two assemblies. The first defines a base class and a series of distinct classes based on the base class. Something similar too: ...
0
by: npthomson | last post by:
Hi all, This could get a bit complicated but I'll try to be as clear as possible. I've written an application that discovers plugins at runtime using reflection from a subdirectory of the...
8
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.