eidylon
eidylon

Reputation: 7238

How can I reference a DLL regardless of version?

Okay, I am a heavy user of Telerik's library of controls, specifically for ASP.NET. However, there is a small bit of functionality which I wanted to add to some of the controls. Nowadays I can do this easy enough using Extension methods. So I wrote a small library which does exactly that. Obviously, this library needs to reference their DLL (Telerik.Web.UI.dll).

In the My Project > References page of my DLL project, I have a reference to Telerik.Web.UI.dll. For this reference, I have the Specific Version property set to False, because I don't want my library to care about what version of the Telerik DLL is being used. THIS is my problem though... the .NET compiler doesn't seem to honor this setting.

Case in point, I have a website which references both the Telerik DLL and mine. I updated the Telerik library to the latest version. Now when I try to run my website, I get:

Could not load file or assembly 'Telerik.Web.UI, Version=2012.1.215.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I fix this by going to my DLL project, recompiling it against the latest Telerik DLL, and then updating my DLL in the website. This is precisely what i didn't want to have to do every time I update Telerik's library. I thought that setting Specific Version to false would mean it would work with any version. No? Or am I completely misunderstanding what that setting does?

Upvotes: 17

Views: 7068

Answers (1)

BluesRockAddict
BluesRockAddict

Reputation: 15683

You should look into using bindingRedirect which will allow you to instruct .NET framework to use another version of assembly at runtime (i.e. if your project was compiled against version 1.0, it would still work with version 1.1, assuming there were no API changes).

Specific Version attribute only applies to compile-time assembly reference.

Upvotes: 4

Related Questions