interviews.dotnetthread.com

↑ Grab this Headline Animator

Thursday, May 8, 2008

Can you place two .dll files with the same name in GAC (Global Assembly Cache)?

Yes, provided both have different versions.

GAC is a Folder that contains .dll that have strong name. So we can keep myproject.dll and myproject.dll two files into GAC with different version like 1.0.0.0 and 1.0.0.1

You need to specify “bindingRedirect” in your config file. For instance in the below case “myproject.dll” has two versions “1.0.0.0” and “1.0.0.1” from which “1.0.0.1” is the recent version. But using the bindingRedirect we can specify saying “1.0.0.0” is the new version. So the client will not use “1.0.0.1”.



Config file code:

























In the above config file code we need to add publicKeyToken. To generate publicKeyToken use “sn –T myproject.dll”.

trick here is to notify the runtime to treat the newer version as older and older as newer

Lets say we have a method and in that method I want to use a function from the older assembly and another function from newer assembly. Is it possible?
Yes, It can be done.

private void btn_Click(object sender, EventArgs e)

{

string str = "early bind - ";

str += ClassLibrary1.Class1.Method1();

MessageBox.Show(str);



AssemblyName asm = new AssemblyName("ClassLibrary1, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=fbc28d9ca2fc8db5");

Assembly al = Assembly.Load(asm);



Type t = al.GetType("ClassLibrary1.Class1");

MethodInfo m = t.GetMethod("Method1");

str = "reflection - " + (string)m.Invoke(null, null);

MessageBox.Show(str);

}



Please read this

http://www.infosysblogs.com/microsoft/2007/04/loading_multiple_versions_of_s.html

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles