Loading Assemblies



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.




Eran Sandler

Hello Gopi,

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

string myFullQualifiedClassName = "MyClass.MyAssembly, MyAssembly,
Version=, 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.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads