473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reflection problem

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
-----------------------------------------------------------------------------

Nov 16 '05 #1
0 935

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
2
by: Marco | last post by:
Hi, I try to use reflection to retrieve class B members and not inherited members. I wonder why the myMember value is nothing. Any suggestions? Thanks Module Module1 Sub Main()
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
7
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system...
5
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.