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:
Assembly sysData = Assembly.Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'); localCmdType = sysData.GetType('System.Data.SqlClient.SqlCommandSet+LocalCommand');
but Activator.CreateInstance throws an exception when I try to instantiate it:
object item = Activator.CreateInstance(localCmdType, new object[] { commandText, parameters, num7, commandType });
System.MissingMethodException: Constructor on type ‘System.Data.SqlClient.SqlCommandSet+LocalCommand’ not found.
The constructor arguments match the signature I see in Reflector. Is new’ing up a private class with an internal ctor supported with a different CreateInstance overload or what?
My first thought would be to get the
ConstructorInfousingConstructorInfo constructorInfo = Type.GetConstructor(), and thenconstructorInfo.Invoke()that. I suspect thatActivator.CreateInstancemakes it hard to call constructors you wouldn’t normally have access to, although I don’t remember trying it myself.