By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,672 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,672 IT Pros & Developers. It's quick & easy.

Activator.CreateInstance problem

P: n/a
ka
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;
}
Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.