How can I get the fully qualified name of an assembly from it's basic name?

Posted by GenericTypeTea on Stack Overflow See other posts from Stack Overflow or by GenericTypeTea
Published on 2010-05-13T10:54:25Z Indexed on 2010/05/13 11:04 UTC
Read the original article Hit count: 225

Filed under:
|
|
|

I'm currently writing a custom forms application that allows a user to design a data capture form. I store the field's ControlType and ControlAssembly in the database and then create them on the forms at runtime.

For example:

ControlType = `System.Web.UI.WebControls.TextBox`.
ControlAssembly= `System.Web`.

So I can therefor create a fully qualified name and create the control doing the following:

string target = Assembly.CreateQualifiedName("System.Web", field.ControlType);
Type type = Type.GetType(target);
Control control = Activator.CreateInstance(type) as Control;

But, this will cause an error as "System.Web" is not a valid assembly name. The assembly name itself has to be fully qualified, i.e. System.Web.Extensions would be:

"System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Is there any way I can get the fully qualified name of the assembly System.Web without having to store the entirity of the version, culture and PKT?

© Stack Overflow or respective owner

Related posts about activator

Related posts about assemblies