I have something along the lines of this:
object[] parameter = new object[1];
parameter[0] = x;
object instantiatedType =
Activator.CreateInstance(typeToInstantiate, parameter);
and
internal class xxx : ICompare<Type>
{
private object[] x;
# region Constructors
internal xxx(object[] x)
{
this.x = x;
}
internal xxx()
{
}
...
}
And I get:
threw exception: System.MissingMethodException: Constructor on type ‘xxxx.xxx’ not found..
Any ideas?
The issue is that
Activator.CreateInstance(Type, object[])does not consider non-public constructors.This is easily shown by changing the constructor to
publicvisibility; the code then works correctly.Here’s one workaround (tested):
If you only require the parameterless constructor this will work as well: