6

Closed

methodInfo.Invoke Crashes VS2010

description

Hello there the code below Crashes VS2010, where it should throw an exception and allow me to catch it... Especially when it is being executed from inside a dynamically loaded Assembly (pe image). trying to invoke a method on the host application. the IDE crashes when you set a break point anywhere inside object InvokeMethod
 
[code]
    object InvokeMethod(string methodName, params object[] args)
    {
        Debug.Print("**********************About to execute this Method=" + methodName);
        try
        {
            var methodInfo = GetType().GetMethod(methodName);

            return methodInfo.Invoke(this, args);
        }
        catch (Exception)
        {
            Debug.Print("Error invoking");
        }
        return null;
    }
public void TestMethod()
    {
        Debug.Print("this is a test");
    }
//now call it like this somewhere in your code:

InvokeMethod("TestMethod");// this will work..

Thread.Sleep(2000);

InvokeMethod("TestMethod",new object[]{"test"});// this will Crash VS2010, because you are passing arguments to a method that doesn't accept any... it shouldn't crash but instead it should trow the exception.

InvokeMethod("UnknowMehod");// this will Crash since you are calling a non existing method... again it should safely land in the Catch but instead it crashes...
 
[/code]
Jay.
 
Thanks.
Closed Sep 19, 2012 at 8:18 PM by ZachLibby
I can not reproduce this issue. If you are still seeing this problem please re-open the issue and add any additional information you can about this issue.

comments

ZachLibby wrote May 4, 2012 at 10:44 PM

I do not see this crash from my v4.2 SDK installation (using the posted code). Which version of MF are you using? I can set breakpoints in InvokeMethod and I correctly get a null reference exception for the "UnknownMethod" case.

Zach