Instantiate Type with internal Constructor with reflection

You can retrieve the constructor via reflection, and invoke it.

var ctor = typeof(Test)
    .GetConstructors(
        BindingFlags.NonPublic | 
        BindingFlags.Public | 
        BindingFlags.Instance
    )
    .First();
var instance = ctor.Invoke(null) as Test;

BindingFlags:

var ctor = typeof(MyType).GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(c => !c.GetParameters().Any());

var instance = (MyType)ctor.Invoke(new object[0]);

The BindingFlags gets the non public constructors. The specific constructor is found via specified parameter types (or rather the lack of parameters). Invoke calls the constructor and returns the new instance.


First, you need to find the constructor:

var ctor = typeof(MyType).GetTypeInfo().GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).Single(x => /*filter by the parameter types*/);
var instance = ctor.Invoke(parameters) as MyType;

Please add a reference to the System.Reflection namespace.