Check for existence of dll and use if found

  • Thread starter Thread starter Daniel Moth
  • Start date Start date
D

Daniel Moth

1. Using System.IO you can check for the existence of dlls in your
application directory.
2. You can then use System.Reflection.Assembly.LoadFrom method to load the
dlls.

MSDN or google will give you more info on the above. If you have any
specific problems feel free to post back.

Cheers
Daniel
 
C#:
Type tObj = yourAssembly.GetType("MyNamespace.MyType");
MethodInfo mi = tObj.GetMethod("MyStaticMethod");
retVal = mi.Invoke(null, new object[] { your parameters here, if any } );

VB#:
Dim tObj as Type = yourAssembly.GetType("MyNamespace.MyType")
Dim mi as MethodInfo = tObj.GetMethod("MyStaticMethod")
Dim Params() as Object
' Populate Params here
retVal = mi.Invoke(Nothing, Params )
 
Hi,
I have an application which consists of a small exe and a number of
dlls. Each dll represents a sort of "plugin" application which can be
launched from the main exe. What I would like to be able to do is (at
runtime) check the application directory for the existence of any/all of
these dlls and present buttons for whichever ones are found on the main
form provided by the exe. If no dlls are found, a blank form would be
shown. Can this be done? At the moment I add project references for each
of these dlls to the main project, then place references to the main
form class from each dll at the top of the exe's main form class. I can
obviously instantiate these classes based on certain conditions being
met, but this still requires that the dlls exist in the first place and
have been included as project references. Is there some way that I can
do this more dynamically, so that the dlls would behave more like plugins?
Thanks,
Shannon
 
Daniel said:
1. Using System.IO you can check for the existence of dlls in your
application directory.
2. You can then use System.Reflection.Assembly.LoadFrom method to load
the dlls.

MSDN or google will give you more info on the above. If you have any
specific problems feel free to post back.

Cheers
Daniel

Thanks for that. I've looked into loading assemblies dynamically, and
this looks like it is going to work. I've found plenty of information
relating to instantiating classes from loaded assemblies, but what about
calling methods within assemblies? Specifically, one of the classes in
one of the dynamically-loaded assemblies has a static method which
returns a custom control which I would like to use. Because the method
is static, I can't use CreateInstance on the class. I'm assuming there
is a simple way to do this, but I'm having some trouble finding it.
Thanks,
Shannon
 
Alex said:
C#:
Type tObj = yourAssembly.GetType("MyNamespace.MyType");
MethodInfo mi = tObj.GetMethod("MyStaticMethod");
retVal = mi.Invoke(null, new object[] { your parameters here, if any } );

VB#:
Dim tObj as Type = yourAssembly.GetType("MyNamespace.MyType")
Dim mi as MethodInfo = tObj.GetMethod("MyStaticMethod")
Dim Params() as Object
' Populate Params here
retVal = mi.Invoke(Nothing, Params )

Cheers. I managed to come up with that eventually, and all is working
perfectly now. Thanks to those who helped.
Shannon
 
Back
Top