I\'m trying to new up a LocalCommand instance which is a private class of System.Data.SqlClient.SqlCommandSet. I seem to be able to grab the type information just fine:
Trick is to make sure to use the right CreateInstance
overload:
// WRONG
... Activator.CreateInstance(
type,
BindingFlags.Instance
| BindingFlags.NonPublic
);
This calls the params
overload, which will default to Instance | Public | CreateInstance
, and your binding flags will be passed as arguments to the constructor, giving the vague MissingMethodException
.
Also, use Instance | Public | NonPublic
if you aren't sure of the visibility of the constructor:
// right
... Activator.CreateInstance(
type,
BindingFlags.Instance
| BindingFlags.Public
| BindingFlags.NonPublic,
null,
new object[] { }, // or your actual constructor arguments
null
);