Overcoming problems with MethodInfo.Invoke of methods with by-reference value type arguments

I ran into an interesting problem on the Forums recently.  Basically, when you use MethodInfo.Invoke to invoke a method with by-reference value type arguments you can’t have the invoked method update a variable/argument.  The problem is, when you invoke the method the parameter is passed to the MethodInfo.Invoke via an object array.  Since we’re dealing with a value type, the original value type is boxed and the invoked method actually updates the array element, not the original object (as it would with reference types).  For example: using System; using System.Reflection.Emit; using System.Reflection; using System.Diagnostics;   namespace InvokeTesting {     class Program     { … Continue reading Overcoming problems with MethodInfo.Invoke of methods with by-reference value type arguments