By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,169 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,169 IT Pros & Developers. It's quick & easy.

dynamically load DLL exception when calling Activator.CreateInstance(type, object[])

P: n/a
I am trying to dynamically load a dll which specifies different rules
for evalution with the following code.
DataRow dr = ds.Tables[0].Rows[0];
string fileName = Convert.ToString(dr["RuleLocation"]);
assemblyInstance = Assembly.Load( fileName );
typeInstance = assemblyInstance.GetType( "MSF.Storefront.Rules." +
dr["RuleName"].ToString() , true, false);
Object[] parameter = new Object[1];
if (seg == null)
parameter[0] = cs;
else
parameter[0] = seg;

rule = (Rules.IBaseRule)Activator.CreateInstance(typeInst ance,
parameter);
return rule;

this code works fine if the rules are existing .cs files in the
current project and it loads it fine. The problem is when the program
is already running and then I add a new rule .dll into the bin folder,
then try to load that rule dynamically. I get an exception.

the exception i get is the MissingMethodException, member cannot be
found. So then i create an empty constructor and pass in only the
typeInstance, i get a CastException. What is wrong? Please help.
Thanks.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Nancy:

If I am reading the description of the problem correctly, then it
sounds as if you are trying to create an instance of a type that is in
an assembly that is not loaded. Are you using Assembly.LoadFile
somewhere to bring that assembly into the process?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 29 Nov 2004 14:44:08 -0800, na******@gmail.com (Nancy Sui) wrote:
I am trying to dynamically load a dll which specifies different rules
for evalution with the following code.
DataRow dr = ds.Tables[0].Rows[0];
string fileName = Convert.ToString(dr["RuleLocation"]);
assemblyInstance = Assembly.Load( fileName );
typeInstance = assemblyInstance.GetType( "MSF.Storefront.Rules." +
dr["RuleName"].ToString() , true, false);
Object[] parameter = new Object[1];
if (seg == null)
parameter[0] = cs;
else
parameter[0] = seg;

rule = (Rules.IBaseRule)Activator.CreateInstance(typeInst ance,
parameter);
return rule;

this code works fine if the rules are existing .cs files in the
current project and it loads it fine. The problem is when the program
is already running and then I add a new rule .dll into the bin folder,
then try to load that rule dynamically. I get an exception.

the exception i get is the MissingMethodException, member cannot be
found. So then i create an empty constructor and pass in only the
typeInstance, i get a CastException. What is wrong? Please help.
Thanks.


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.