Suppose I have a factory method that wants to build an instance of the type selected at runtime through reflection. Suppose further that my factory method is generic code that does not directly reference the assembly that contains the specified type, although it will be launched from an application that has the required assembly.
How can I write code that can find this type? If I do the following
public object CreateInstance(string typeName)
{
Type desiredType = Assembly.GetExecutingAssembly().GetType(typename);
}
this seems to fail because the type is not defined in the runtime assembly. If I could get all the assemblies available at run time, I could iterate over them and find which one contains the type that I want. But I do not see a way to do this. AppDomain.CurrentDomain.GetAssemblies()It looks promising, but does not return all the assemblies that I referenced in my project.
Change . Several people indicated that I needed to download the assembly. The problem is that this piece of code does not know which assembly it should load, since I am trying to write this code in such a way that it does not depend on other assemblies.
typeName, . , , , , .