string classname = "SimpleClassLibrary1.Class1";I mentioned in my other reply about the use of interfaces. If you didn't use an interface that was common to a known set of dynamically instantiated objects, then you'd have to have a reference in your solution to Class1 ... which defeats the purpose of what we're trying to accomplish here.
namespace SimpleClassLibrary1 { public class Class1 : IShowMessage { //method public bool showmessageX(string message) { MessageBox.Show(message); return true; } } }And you'd instantiate and call the method like this:
IShowMessage o = oReflection.InstantiateClass(ref message) as IShowMessage; if (o == null) MessageBox.Show(message); else { o.showmessageX(message); }Does that help?
>namespace SimpleClassLibrary1 >{ > public class Class1 > { > //method > public bool showmessageX(string message) > { > MessageBox.Show(message); > return true; > } > } >} >>
>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 > > } > } >>
>object o = oReflection.InstantiateClass(ref message);
>
>>// 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.>if (oAssembly != null) > oClass = oAssembly.CreateInstance(this.m_ClassName); >>