Reflection on internal, overload and with ref parameters method

How to obtain a reference to the method System.Web.Configuration.MachineKey.GetEncodedData using .net v1.1?

With the following code it returns null:

Type t = typeof(System.Web.Configuration.HttpCapabilitiesBase)
    .Assembly
    .GetType("System.Web.Configuration.MachineKey");

MethodInfo method = t.GetMethod("GetEncodedData",
    BindingFlags.NonPublic | BindingFlags.Static, 
    null,
    new Type[] { typeof(byte[]), typeof(byte[]), typeof(int), typeof(int) },
    new ParameterModifier[0]
);
Jon Skeet
people
quotationmark

Okay, so it sounds like the problem is that there's no equivalent of Type.MakeByRef in .NET 1.1.

You may be able to use Type.GetType("System.Int32&") to get that:

MethodInfo method = t.GetMethod("GetEncodedData",
    BindingFlags.NonPublic | BindingFlags.Static, 
    null,
    new Type[] { typeof(byte[]), typeof(byte[]),
                 typeof(int), Type.GetType("System.Int32&" },
    new ParameterModifier[0]
);

Alternatively, you could always create your own method (which you can find using just GetMethods for example) with a ref int parameter, and use that parameter type. Icky, but...

All of this feels very brittle to start with, of course. I assume you've got a really good reason for wanting to invoke an internal method on a pretty-much-obsolete version of the framework...

people

See more on this question at Stackoverflow