Professional Web Applications Themes

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

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 ...

  1. #1

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

    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.
    Nancy Sui Guest

  2. #2

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


    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
    [url]http://www.OdeToCode.com/blogs/scott/[/url]

    On 29 Nov 2004 14:44:08 -0800, [email]nanirina[/email] (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.
    Scott Allen Guest

Similar Threads

  1. Replies: 2
    Last Post: June 6th, 04:02 PM
  2. C# exception after calling Java/Axis web service
    By Amil in forum ASP.NET Web Services
    Replies: 3
    Last Post: April 19th, 07:52 PM
  3. Web Service Calling a COM object-throws exception.
    By Chris Bardon in forum ASP.NET Web Services
    Replies: 1
    Last Post: February 28th, 12:31 AM
  4. Security Error When calling assembly.CreateInstance
    By Roman in forum ASP.NET Security
    Replies: 3
    Last Post: November 19th, 06:54 PM
  5. Replies: 1
    Last Post: October 20th, 04:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139