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.CreateInstance will be failed ?? I only create a
System.Windows.Forms.Label. I've verified the type passed in is correct.
public System.ComponentModel.IComponent CreateComponent(System.Type
componentClass, string name)
{
IComponent component = null;
// Create instance // problem here
component = Activator.CreateInstance(componentClass) as IComponent;
//validation name
INameCreationService nameCreationService = (INameCreationService)
GetService(typeof(INameCreationService));
if (!nameCreationService.IsValidName(name))
{
name = nameCreationService.CreateName(container, componentClass);
}
// Add to design container
container.Add(component, name);
return component;
}