I am writing an application in which user has to browse for a dll to be used. Then if that dll does not contain the required method definition an error message is to be shown. I used following code :
private void CheckDll()
{
string dllName;
string methodName;
bool isMethodFound = false;
OpenFileDialog browseFile = new OpenFileDialog();
browseFile.Filter = "DLL : |*.dll;*.DLL |OCX Files| *.ocx|All File|*.*";
try
{
if (browseFile.ShowDialog() != DialogResult.Cancel)
{
methodName = CommonMod.GetMethodName(1);
dllName = browseFile.FileName;
Assembly loadedDll = Assembly.LoadFile(dllName);
foreach (Type memberType in loadedDll.GetTypes())
{
if (memberType.IsClass)
{
MethodInfo method = memberType.GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);
if (method != null)
{
isMethodFound = true;
}
}
}
if (!isMethodFound)
{
MessageBox.Show(methodName + " method not found in DLL.", "Script Generator", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
Debug.Print(e.Message);
}
}
}
}
This works fine with .net DLLs but with VB dll it fails, is there a way to do it for vb DLLs. thanks in advance.