Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help needed with Reflection
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01250136
Message ID:
01250160
Views:
26
Hi Pete,

Maybe you'll try creating a new 'PJKTabPage' object first and then assign it.

This is what I mean:
...
PJKTabPage oTP = new PJKTabPage();
oTP = Activator.CreateInstance(type) as PJKTabPage;
...
HTH


>Hi All, I'm trying to dynamically load some TabPages that are defined in seperate dlls using the code below, the problem I'm having is with the line : "PJKTabPage oTP = Activator.CreateInstance(type) as PJKTabPage;" where PJKTabPage is the name of the class, the class loads ok ( I've stepped through the code with the debugger ) but the variable oTP is always null, can't understand why ?
>
>
>
>private void frmPluginTest_Load(object sender, EventArgs e)
>{
>    string[] dllFilenames = Directory.GetFiles(@"P:\PJKPlugin\TabPagePlugins","TabPage*.dll");
>    foreach (string filename in dllFilenames)
>    {
>        try
>        {
>            Assembly asm = Assembly.LoadFrom(filename);
>            Type[] typesInAssembly = asm.GetTypes();
>            foreach (Type type in typesInAssembly)
>            {
>                 if (null != type.GetInterface(typeof(PJKPlugins.ICMSTabPage).FullName))
>                 {
>                      PJKTabPage oTP = Activator.CreateInstance(type) as PJKTabPage;
>                      this.PluginTabControl.Controls.Add(oTP);
>                 }
>             }
>         }
>         catch
>         {
>              // Not a valid assembly, move on
>         }
>    }
>}
>
robert.oh.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform