6
Ho una classe al di sotto,C#: System.Reflection.MethodInfo causa: (oggetto non corrisponde tipo di destinazione)
namespace PocketWeb.AppClass
{
public class ApiBase
{
public string foo(string s)
{
return s;
}
}
}
e invito via System.Reflection.MethodInfo di sotto, ma causo TargetException: Object non corrisponde al tipo di destinazione.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var instance_class = Activator.CreateInstance(Type.GetType("PocketWeb.AppClass.ApiBase"));
Type instance_method = instance_class.GetType();
System.Reflection.MethodInfo theMethod = instance_method.GetMethod("foo");
object[] obj = new object[] { "hello" };
Response.Write(theMethod.Invoke(this, obj)); //<---Error
}
}
Quindi qualche idea? Ho provato a cambiare il parametro di foo per obiettare come: foo (object s) {}, ma non aiuta.
Ottimo lavoro ~~ mi hai salvato, amico ~ – Cheung