Loading Assemblies

  • Thread starter Thread starter Gopi
  • Start date Start date
G

Gopi

Hi,
I have a private assembly (which is there in ny
application's bin directory) which is signed with a strong
name. I want to load that assembly by using its valid
fully qualified assembly name as shown below.

SampleAssembly = Assembly.Load("Assembly text name,
Version, Culture, PublicKeyToken");

This requires assembly to be placed in the GAC. I don't
want to do that. Pls let me know how can I load an
assembly by using its local file path and fully qualified
name together.

TIA
-Gopi
 
Hello Gopi,

If I'm not mistaken, you can use the following method:

string myFullQualifiedClassName = "MyClass.MyAssembly, MyAssembly,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcde";

Type t = Type.GetType(myFullQualifiedClassName);
object myInstance = Activator.CreateInstance(t);

This will automatically load the assembly if its not loaded. It will first
search for it in the GAC and if it won't find it there, it will search the
application's bin directory or any other search path you have entered.

Of course, the CreateInstance method will only work if you have a default
constructor without any parameters. If your constructor does have
parameters, you can use reflection to run it with the necessary parameters.

Hope this helps a bit.
 
Back
Top