I'm implementing an IDesignerHost, for the CreateComponent method. The code
below is quite standard. When loading a form, the CreateComponent works
fine. However, when someone choose a control from the toolbox, the Activator
couldn't create the component and returns null in CreateInstance. In what
scenario, Activator.Creat eInstance will be failed ?? I only create a
System.Windows. Forms.Label. I've verified the type passed in is correct.
public System.Componen tModel.ICompone nt CreateComponent (System.Type
componentClass, string name)
{
IComponent component = null;
// Create instance // problem here
component = Activator.Creat eInstance(compo nentClass) as IComponent;
//validation name
INameCreationSe rvice nameCreationSer vice = (INameCreationS ervice)
GetService(type of(INameCreatio nService));
if (!nameCreationS ervice.IsValidN ame(name))
{
name = nameCreationSer vice.CreateName (container, componentClass) ;
}
// Add to design container
container.Add(c omponent, name);
return component;
}
below is quite standard. When loading a form, the CreateComponent works
fine. However, when someone choose a control from the toolbox, the Activator
couldn't create the component and returns null in CreateInstance. In what
scenario, Activator.Creat eInstance will be failed ?? I only create a
System.Windows. Forms.Label. I've verified the type passed in is correct.
public System.Componen tModel.ICompone nt CreateComponent (System.Type
componentClass, string name)
{
IComponent component = null;
// Create instance // problem here
component = Activator.Creat eInstance(compo nentClass) as IComponent;
//validation name
INameCreationSe rvice nameCreationSer vice = (INameCreationS ervice)
GetService(type of(INameCreatio nService));
if (!nameCreationS ervice.IsValidN ame(name))
{
name = nameCreationSer vice.CreateName (container, componentClass) ;
}
// Add to design container
container.Add(c omponent, name);
return component;
}