Hi All,
I have a function that I need to call on reflection that has an out
parameter
(maybe more than one).
My problem is that I'm not receiving the out values.
The following code works fine on VS2003, but not on 2005:
ArrayList myArgs = new ArrayList();
Int outVal;
myArgs.Add( outVal );
obj.GetType().InvokeMember( "GetValue",
BindingFlags.SetProperty | BindingFlags.Public |
BindingFlags.Instance,
null,
obj,
(Object [])myArgs.ToArray(typeof(Object)) // FAILS ON 2005
value always returns 0
);
However, this fixes the problem:
object [] myArgs = {new int() };
obj.GetType().InvokeMember( "Memory",
BindingFlags.SetProperty | BindingFlags.Public |
BindingFlags.Instance,
null,
obj,
myArgs) // WORKS FINE
);
I guess this is related to a temporary array that is returned from
'ToArray()' and gets lost,
but I still don't really understand what's happening there.
Can anyone please explain to me what's exactly happening behind the
scenes, or point me to some links?
Thanks a lot!