Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table Driven Menus
Message
From
19/11/2009 23:21:51
 
 
To
19/11/2009 11:28:21
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01435073
Message ID:
01435741
Views:
33
>Hey Bernard,
>
>Yep, you can do exactly that! The only caveat is that you must instantiate your new DLL using Reflection, which is pretty easy too. I've posted code here many times for this, and I finally wrote it up in my blog a couple of months ago: http://geek-goddess-bonnie.blogspot.com/2009/09/reflection-in-net.html
>
>~~Bonnie
>

Hi Bonnie

After reading your blog this is what I did:

1. I created a class which will be dynamically loaded and its methods called using reflection - SimpleClassLibrary1 and compiled it to a DLL and closed the project.
namespace SimpleClassLibrary1
{
    public class Class1
    {
        //method
        public bool showmessageX(string message)
        {
            MessageBox.Show(message);
            return true; 
        }
    }
}
2. I then created a new solution and created your MyReflectionClass exactly as you showed in your blog. The only change is I called it bbReflection.

3. I added a new windows forms project to the above solution and added a reference to the above assembly called bbReflection

4. On the form I added a button and in its click added this code to test:
private void button1_Click(object sender, EventArgs e)
        {
            string assembly = "C:\\VSX2008\\MyProjects\\bbReflection\\SimpleClassLibrary1\\bin\\Release\\SimpleClassLibrary1.dll";
            string classname = "class1";
            MyReflectionClass oReflection = new MyReflectionClass(assembly, classname);

            string message = "";
            object o = oReflection.InstantiateClass(ref message);
            if (o == null)
                MessageBox.Show(message);
            else
            {
                // go on with your processing
                
            }
        }
Everything compiles ok (no errors) but when I click the button, a message box with nothing appears. On stepping through the code, it is because
object o = oReflection.InstantiateClass(ref message);
always returns null.

What am I doing wrong here?

All I want to do is in the part where you have
// go on with your processing
I want to call the method in bbReflection.Class1 - showmessageX to display the message, but it never runs that code because o is always null.

and this is because of this - oAssembly is not null but the CreateInstance returns null always.
if (oAssembly != null)
       oClass = oAssembly.CreateInstance(this.m_ClassName);
Also what would be the syntax for calling the showmessageX method passing it a message to display?

Please help.

Bernard
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform