|
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.Application.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
|
|
|
|
|
|
thanx for the quick reply.
the method tries to create/update certain records in a oracle db. FYI, i've tested the same dll by other means (without using reflection) and found them working alright.
|
|
|
|
|
But what is the method name at the time that Invoke doesn't seem to return? Use a debugger (like Visual Studio .NET - just hit F5) and step through the code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
There are about 12 methods in that dll and i've tried calling about five different methods...it happens with all those five...so, i belive the problem is not method-specific...
FYI, the OS is Windows2003..could it have any effect?
Thanx,
Ananth
|
|
|
|
|
AnanthRK wrote:
FYI, the OS is Windows2003..could it have any effect?
No, not on a (mostly) platform-dependent framework. Besides, reflection is platform-independent.
I see several problems with your original code. First, why do you get a second MethodInfo by name when you already have a MethodInfo (the current one you're looping through in your foreach )? You never do check for null in cases where you should (making sure you get a MethodInfo for a named method, for example).
Also keep in mind that Type.GetMethods() - with no parameters - gets only public instance methods defined on that Type.
Finally, change your catch and get the whole exception, not some friendly error message. These are much more helpful when debugging. A TargetInvocationException can happen for many reasons. Knowing the exact reason (the Message and InnerException properties, if the latter is assigned) will be greatly more helpful.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
How can I use c# to insert,update,delete,select Xml Node like operate database?
Is there some examples?
thanks!
|
|
|
|
|
Non-specific questions like these are best answered by reading the .NET Framework SDK, specifically sections like Employing XML in the .NET Framework[^]. This sections includes many topical articles, examples, and links to class library documentation which is very important to read.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
We have problems with two software packages. Both packages require the .NET framework be installed. Both vendors software works great for the ADMIN, but both throw exceptions for users that are not ADMIN.
Can you point me in the right direction?
thanks
|
|
|
|
|
I'm pretty sure your program tries to do something which is denied by the OS and as a result the exception is thrown.
It would be helpful to know which exceptions are thrown and even more important which operations caused them.
www.troschuetz.de
|
|
|
|
|
|
Can you point me in the right direction?
Another vendor? Unless you specifically need the applications to do admin-type things, it is inexcusable for commercial .NET software to require admin rights.
my blog
|
|
|
|
|
It's inexcusable for any application to require admin rights if, indeed, it doesn't require them (i.e., a system management package would most likely require admin rights, and justly so).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Because software must be careful about requiring admin privileges (for example, why should calc.exe require admin privileges), you must be careful about using features that require admin privileges. This includes writing user preferences or data to protected registry hives (like HKEY_LOCAL_MACHINE) or directories (like %WINDIR%), and many more.
If, at times, your software requires admin privileges, either be prepared to catch SecurityException or similar exceptions (the BCL method documentation should state what could be thrown), or use Code Access Security (CAS) - namely the PrincipalPermission , to either declaratively or imperatively demand permissions with a certain group.
A good starting point to learn CAS is Understanding .NET Code Access Security[^] right here on CodeProject. Be sure to follow the links.
So, if you had a method that required Admin privileges (say to enumerate a certain protected DC in Active Directory), you could code your method like so:
[PrincipalPermission(SecurityAction.Demand, Role="Administrators")]
public IEnumerator GetADEnumerator(string path)
{
} Do note that using the PrincipalPermissionAttribute or PrincipalPermission (for declarative security) does require to either hard-code a domain name (i.e., "MYDOMAIN\Domain Admins") or to use a local group where a domain or machine name isn't required).
In these cases, catch exceptions is a better choice (and should be done anyway since calling a protected method using CAS will still throw an exception).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello! I'm using a listView to display some objects and i have in each row a checkbox control. I want to remove the selection of one item so that the only control selection on the listview is the checkbox. I another way i want the item doesn't turn blue when selected and the only way of selection is the checkbox.
Thanks !!
Bruno Conde
|
|
|
|
|
hi,
Lot of article are there in codeproject which help you to play with listview.
I can give an exact match for you. Please check this url for your purpose.
http://www.codeproject.com/listctrl/supergrid.asp
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I have an app with a few forms all of which can be opened at the same time. From the starting form a blocking socket class is initialised in a new thread, and this class raises different data received events handled by the different forms depending on the data received.
The problem is one form adds the data to a datagrid and whenever this event is consumed this form comes to the front. this does not happen with the other forms.
So the question is why does this happen and how can I stop it?
|
|
|
|
|
hi,
You can check the property TopMost property of you form. Check it's status.;)
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Top most is set to false, and I don't change it in code.
But thanks for the suggestion, it rules something out.
|
|
|
|
|
hi,
generall we should use process attach tools when debuging service program,
but it's not always available.
could i write some extra code to enter into service main procedure directly,
so i can gain some more debug information.
|
|
|
|
|
Sure,
a log file comes to mind.
Or writing to the event log (but then the messages shouldn't be too long).
Regards,
mav
|
|
|
|
|
i want to delete selected row by pressing delete button on keyboard ...also i want to know the evet when deleteing row on datagrid ...
|
|
|
|
|
hi,
You can't delete a row from datagrid( datagrid row). What you can do is, when user hit the delete key then can delete one record from the data source ( Datatable or view) which use to show the data in datagrid and then you need to re define the datagrid's datasource.
Write your logic in datagrids keydown event.
if(e.KeyValue== Keys.Delete)
{
}
Better if you go through Datagrid HitInfo or HitTestInfo methods.;)
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I want to serialize a private field of a class:
...
private ArrayList items = null;
...
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
TextWriter writer = new StreamWriter(path);
serializer.Serialize(writer, this);
writer.Close();
the items array is serialized only if change it to public, but I do not want to do this.
items are presented by the class through some properties, each making some work before
returns something; the basic form of items should not be visible.
Any solution?
|
|
|
|
|
I'm not sure why you're using the XML serializer for this, but here goes...
XML serialization is not designed to access private class members. If you want to force XML serialization to store private class mambers, you may be able to do so using the IXmlSerializable interface see here[^] for a little more info.
If XML serialization is not a requirement, you might consider binary serialization. There's much better support for customizing the serialization process built into the framework (and documented).
Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|