I have the following class (as shown through a reflector)
public class W : IDisposable
{
public W(string s);
public W(string s, byte[] data);
[MethodImpl(MethodImplOptions.InternalCall)]
internal extern W(string s, int i);
public static W Func(string s, int i);
}
I am trying to call the constructor "internal extern" or Func using reflections
MethodInfo dynMethod = typeof(W).GetMethod("Func", BindingFlags.Static);
object[] argVals = new object[] { "hi", 1 };
dynMethod.Invoke(null, argVals);
and
Type type = typeof(W);
Type[] argTypes = new Type[] { typeof(System.String), typeof(System.Int32) };
ConstructorInfo dynMethod = type.GetConstructor(BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, argTypes, null);
object[] argVals = new object[] { "hi", 1 };
dynMethod.Invoke(null, argVals);
unfortunately, both options raise a NullReferenceException when trying to call, so should I do something wrong?
source
share