Hi guys.
I'm trying to call a static method dynamically and found this code in the Csla MethodCaller class.
public static object CallMethod(
object obj, MethodInfo info, params object[] parameters)
{
// call a private method on the object
object result;
try
{
result = info.Invoke(obj, parameters);
}
catch (Exception e)
{
throw new Csla.Server.CallMethodException(
info.Name + " " + Resources.MethodCallFailed, e.InnerException);
}
return result;
}
What caught my attention is the parms object[] part as I had not seen it before. The method I am trying to invoke is actually a Csla Factory method on one of my business objects. I have all the parameters in a criteria object and so I wrote a method, using the example above, like this:-
public object CallMethod(MethodInfo info, params object[] parameters)
{
return info.Invoke(null, parameters);
}
The static method I am trying to invoke takes one parameter, a Guid. If I step into this code I can see I have a valid MethodInfo for the method, and the parameters parameter is correctly identified as MyObject.Criteria. I can drill down into that and see that the array is one dimension deep and contains a Guid. However, the code spits out an error that it cannot convert an object of type MyObject.Criteria to a Guid. The Csla code works great, and everything I can find on this way of calling a method seems to indicate that what I have done should work. So anyone out there know why it blows up?
TIA.
Final thought: I just made a quick Test rig to Test this outside my project and get the same result. Please see attached code.
Copyright (c) Marimer LLC