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] >
>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?
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.