I am calling methodInfo.Invoke as per code below which works.
object[] wizParams = { wiz,e, Page};
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "bin\\", assembly);
Assembly asm = Assembly.LoadFile(path);
foreach (Type t in asm.GetTypes())
{
if (t.Name == className)
{
//getmethod has some useful overloads
//also GetMethods() returns a MethodInfo[] array containing all methods
MethodInfo mi = t.GetMethod(method);
if (mi == null)
continue;
//Method sign must be generic
try
{
object result = mi.Invoke(null, wizParams);
}
catch (Exception ex)
{
Helpers.EventLogHelper.WriteEventLog("Failed to call class method " + className + "." + method + ex.Message);
}
However within one of my dynamic methods that is called, I am referencing a customProfile property like
CustomProfileHelper.GetProfile().User.ClientId
The CustomProfileHelper has a base class of ProfileBase. When referenced outside of the invoked method the ProfileHelper returns the value contained so....
Am looking for an explanation as to why the castExceptions occurs within the method when the type is correct and a possible fix :) ?
david steele
Member
19 Points
19 Posts
InvalidCastException when calling methodInfo.Invoke
Jan 16, 2013 06:48 PM|LINK
Hi All,
I am calling methodInfo.Invoke as per code below which works.
object[] wizParams = { wiz,e, Page}; string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "bin\\", assembly); Assembly asm = Assembly.LoadFile(path); foreach (Type t in asm.GetTypes()) { if (t.Name == className) { //getmethod has some useful overloads //also GetMethods() returns a MethodInfo[] array containing all methods MethodInfo mi = t.GetMethod(method); if (mi == null) continue; //Method sign must be generic try { object result = mi.Invoke(null, wizParams); } catch (Exception ex) { Helpers.EventLogHelper.WriteEventLog("Failed to call class method " + className + "." + method + ex.Message); }However within one of my dynamic methods that is called, I am referencing a customProfile property like
The CustomProfileHelper has a base class of ProfileBase. When referenced outside of the invoked method the ProfileHelper returns the value contained so....
Am looking for an explanation as to why the castExceptions occurs within the method when the type is correct and a possible fix :) ?
Thanks
Paul Linton
Star
13431 Points
2535 Posts
Re: InvalidCastException when calling methodInfo.Invoke
Jan 22, 2013 03:40 AM|LINK
Which line throws the Exception? I can't see any code that does any casting.