Hello group,
Here is the scenario...
There is a .dll (written in C#) available in the same folder as my
application.I'm using reflection to dynamically load the assembly and call
the methods available in that dll.
However, the system hangs when it is trying to call the methods in that dll.
FYI, i'm able to successfully create an object for the dll's class. The
problem is in the line i call the "Invoke" method. That is, the control is
NOT passing to the next line after "Invoke" and it remains in the same line
for an infinite amount of time. I've attached the method (at the end of this
post) for your reference.
Any suggestions would be greatly appreciated.
Thanx,
Ananth
------------------------------------------------------------------------------
//Method starts here
private string CallFunction(string assemblyPath, string className, string
methodName, string[] param)
{
try
{
if (! System.IO.File.Exists(System.Windows.Forms.Applica tion.StartupPath +
"\\" + assemblyPath))
{
return "The dll is not found in the installation directory.";
}
else
{
assemblyPath = System.Windows.Forms.Application.StartupPath + "\\" +
assemblyPath;
}
Assembly objAssembly = Assembly.LoadFrom(assemblyPath);
if (objAssembly == null)
return "";
AssemblyName objAssemblyName = objAssembly.GetName();
string strAssemblyShortName = "" + objAssemblyName.Name;
objAssemblyName = null;
Type objType = objAssembly.GetType(strAssemblyShortName + "." + className);
object o = Activator.CreateInstance(objType);
int ct = param.Length;
object[] paramObj = new object[ct];
for (int i=0;i<ct;i++)
{
paramObj[i] = (object)param[i];
}//for i
string sResult = string.Empty;
MethodInfo[] arrMethods = objType.GetMethods();
foreach (MethodInfo objMethod in arrMethods)
{
if (objMethod.Name == methodName)
{
MethodInfo t = objType.GetMethod(methodName);
sResult = "" + t.Invoke(o, paramObj).ToString();
return sResult;
}
}
}
catch(TargetInvocationException tex)
{
string strMsg = "Error occured while calling " + className + "." +
methodName;
}
catch(Exception ex)
{
string strMsg = "Error occured while calling " + className + "." +
methodName;
}
return "";
}
//Method ends here
-----------------------------------------------------------------------------