dynamic DLL loading

P

Pohihihi

I want to enable a button for some funtionality in my main application by
checking if a perticular assembly is installed or not. I have following
code --

Assembly a = Assembly.LoadFrom("DLLHello.dll");
Type[] myTypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
foreach( Type t in myTypes )
{
ConstructorInfo[] ci = t.GetConstructors();
object obj = Activator.CreateInstance(t);
foreach(ConstructorInfo c in ci)
{
c.Invoke(obj,null);
}
}

Very much from MSDN but I am stuck after first foreach loop.

My problem is how to get instance of my class and all the methods inside it,
like I can get by ref at design time !!

Thanks
 
P

Pohihihi

Thanks Octavio.


Octavio Hernandez said:
Hi,

Use a.GetType("YourClass")

Regards - Octavio

Pohihihi said:
I want to enable a button for some funtionality in my main application by
checking if a perticular assembly is installed or not. I have following
code --

Assembly a = Assembly.LoadFrom("DLLHello.dll");
Type[] myTypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
foreach( Type t in myTypes )
{
ConstructorInfo[] ci = t.GetConstructors();
object obj = Activator.CreateInstance(t);
foreach(ConstructorInfo c in ci)
{
c.Invoke(obj,null);
}
}

Very much from MSDN but I am stuck after first foreach loop.

My problem is how to get instance of my class and all the methods inside
it, like I can get by ref at design time !!

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top