views:

37

answers:

1

I am invoking one of the functions from assembly but I am getting MissingMethodException. I have open exe in .netreflector and show that function is available at right place though it is giving error. Here is the code.

private void button2_Click(object sender, EventArgs e)
 {
        Assembly obj = Assembly.LoadFrom("Solo4O.exe");
        Type datacrypt = obj.GetType("Orch.DC");

        object[] objects = new object[3];

....

        datacrypt.InvokeMember("GetCryptedXML", BindingFlags.InvokeMethod |
                                                BindingFlags.Static |
                                                BindingFlags.Public,
                               null, datacrypt, objects, null);

}
+2  A: 

Your target argument is datacrypt but it should be null, as you're calling a static method (and you're definitely not calling a method on datacrypt).

Beyond that, it's hard to know exactly what's wrong, partly because you haven't shown how you've initialized objects... we don't know what the types involved are. Please show more code. I strongly suspect that one of your argument types is invalid for the method call.

Jon Skeet
@Akie: And how big is the `objects` array? It would really help if you could come up with a short but compelte program which demonstrates the problem...
Jon Skeet
@Akie: Please edit your question, using full formatting, rather than writing in comments. Also make sure you've actually given all the required code - I want to be able to build and run the code you provide. Please read http://tinyurl.com/so-hints
Jon Skeet
Hi Jon, I have updated main thread with full code. Thanks.
Akie
@Akie: Did you read the link I sent you? The code you've given still won't compile without me performing a bunch of changes...
Jon Skeet
Solved.. Problem was third argument of called function. I had declared it in my project and I was passing it explicitly instead of creating it dynamically. Hence, it was not able to find function with correct match of arguments. I have created third argument by calling GetField. Anyways, thanks for your reply Jon.
Akie