Groups | Blog | Home
all groups > asp.net security > november 2004 >

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



nanirina NO[at]SPAM gmail.com
11/29/2004 2:44:08 PM
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(typeInstance,
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.
Scott Allen
11/29/2004 8:44:29 PM

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/

[quoted text, click to view]
AddThis Social Bookmark Button