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.