all groups > vj# > february 2004 >
You're in the

vj#

group:

System.Reflection.TargetInvokeException


System.Reflection.TargetInvokeException Sushi
2/13/2004 4:21:20 AM
vj#:
I am gettting System.Reflection.TargetInvokeException in the following code

Type myType = BuildDynAssembly(); // This retrurns type
Object ptInstance = Activator.CreateInstance(myType, new Object[] { (Int32)(0), (Int32)(0) });
myType.InvokeMember("PointMain", BindingFlags.InvokeMethod, null, ptInstance, new Object[0])

Similar C# code is working
But j# code is giving System.Reflection.TargetInvokeException in the last line i.e
myType.InvokeMember("PointMain", BindingFlags.InvokeMethod, null, ptInstance, new Object[0])

Please help m
Thank
RE: System.Reflection.TargetInvokeException Sushi
2/13/2004 10:01:14 PM
I tried it bur it is giving 'This expression can cause side effects so is not evaluated' in the inner expression field
Actually the exception is caused because the WritePoint function takes no arguments. I am not able to understand what should i pass as last argument in Invoke funtion

Type ptType = CreateDynamicType();
Object ptInstance = Activator.CreateInstance(ptType, ctorParams)
ptType.InvokeMember("WritePoint", BindingFlags.InvokeMethod, null, ptInstance, new Object[0])

It gives same expression even if i pass null
Can any one help me

Thank
RE: System.Reflection.TargetInvokeException rlacas NO[at]SPAM online.microsoft.com
2/13/2004 11:41:18 PM
From MSDN (what is the inner exception?):

Remarks
TargetInvocationException uses the HRESULT COR_E_TARGETINVOCATION which has
the value 0x80131604.

When created, the TargetInvocationException is passed a reference to the
exception thrown by the method invoked through reflection. The
InnerException property holds the underlying exception.


[quoted text, click to view]
code.

Type myType = BuildDynAssembly(); // This retrurns type.
Object ptInstance = Activator.CreateInstance(myType, new Object[] {
(Int32)(0), (Int32)(0) });
myType.InvokeMember("PointMain", BindingFlags.InvokeMethod, null,
ptInstance, new Object[0]);

Similar C# code is working.
But j# code is giving System.Reflection.TargetInvokeException in the last
line i.e.
myType.InvokeMember("PointMain", BindingFlags.InvokeMethod, null,
ptInstance, new Object[0]);

Please help me
Thanks

[quoted text, click to view]

Bob LaCasse
Microsoft Developer Support - Visual J#.NET

This posting is provided AS IS with no warranties, and confers no rights.
RE: System.Reflection.TargetInvokeException rlacas NO[at]SPAM online.microsoft.com
2/19/2004 1:39:22 AM
What is the "CreateDynamicType()" method? I don't see that in the .net fx
docs ...

To answer the basic question, you pass null if there are no parameters.

(More Remarks)
Remarks
A TargetException is thrown when an attempt is made to invoke a non-static
method on a null object. This may occur because the caller does not have
access to the member, or because the target does not define the member, and
so on.

If you get the same problem passing a null parameter array, then check
these things:
- Is the method accessible to your code?
- Is the instance object null?
- Are the type id's for both the type objects the same?

It is possible to have a runtime identity conflict between two instances of
the same type. For example, if one instance is created from a compile-time
reference that is loaded from location A, and another is instance is
created dynamically from an assembly at location B, the two objects would
be created from different files and hence, different physical locations.
This could also cause problems if you were to create an instance with one
type object and invoke a method on that instance with the other type
object, even though both represent the same class definition, for example,
but were loaded from different locations.

If you have only one copy of a test assembly and that same assembly is the
one you use to invoke the method, you can rule out the above scenario for
testing purposes. And, actually, use of Assembly.LoadFrom and kind is
usually the only thing that will cause problems like that. If you always
let the CLR do the load and bind, you should not see the
same-type/different-location issue.

Here is possibly a simpler test app:

package TestApp;

public class AppClass
{
public static void main(String[] args)
{
Object obj =
System.Activator.CreateInstance(
System.Type.GetType(
"TestApp.AppClass"
));

obj.GetType().InvokeMember("run",
System.Reflection.BindingFlags.InvokeMethod,
null,
obj,
null);
}

public void run()
{
System.out.println("run");
}
}




[quoted text, click to view]
not evaluated' in the inner expression field.
Actually the exception is caused because the WritePoint function takes no
arguments. I am not able to understand what should i pass as last argument
in Invoke funtion.

Type ptType = CreateDynamicType();
Object ptInstance = Activator.CreateInstance(ptType, ctorParams);
ptType.InvokeMember("WritePoint", BindingFlags.InvokeMethod, null,
ptInstance, new Object[0]);

It gives same expression even if i pass null.
Can any one help me?

Thanks

[quoted text, click to view]

Bob LaCasse
Microsoft Developer Support - Visual J#.NET

This posting is provided AS IS with no warranties, and confers no rights.
AddThis Social Bookmark Button