CreateInstance with params

  • Thread starter Thread starter Ondrej Sevecek
  • Start date Start date
O

Ondrej Sevecek

This returns exception about constructor not found:



Object[] inputParameters = new Object[] { this, tabControl };


System.Runtime.Remoting.ObjectHandle objectHandle =
System.Activator.CreateInstance( null, "NameSpace.DynamicallyLoadedClass",
inputParameters);





class DynamicallyLoadedClass

{

DynamicallyLoadedClass( Form callerForm, TabControl tabControl)

{

//some constructor code...

}

}



How to come across this problem?

Many thanks Ondra.
 
Ondrej Sevecek said:
This returns exception about constructor not found:

Object[] inputParameters = new Object[] { this, tabControl };


System.Runtime.Remoting.ObjectHandle objectHandle =
System.Activator.CreateInstance( null, "NameSpace.DynamicallyLoadedClass",
inputParameters);

That looks for a default constructor (i.e. a parameterless one) - the
array of objects is for activation attributes, not constructor
parameters.

You could use the version of CreateInstance which takes loads of
parameters, if you like.

If you're not actually going to do remoting with it, I'd just use
Type.GetConstructor to find the appropriate constructor, and then call
Invoke on that.
 
Back
Top