0

I've searched a lot but wasn't able to find a solution yet.

We have a lot of programs for our clients with shared libs (dlls) in one directory. But if one lib gets an update we have to recompile all programs which are refering the dll. If we don't, our client get's an error when calling a function from the lib (The located assembly's manifest definition does not match the assembly reference).

We would like to reference a lib as usual and when a lib get's upgraded the programs should just use the new version instead of throwing an error.

Part of the problem is, that the reference is internally fixed with an version-number. My first idea is to remove the version number of the dll before refering. But is that even possible?

I would be grateful for any (other) ideas or suggestions how to bypass the reference problem. This may be a duplicate but I didn't yet find a post with an solution - just post's which describe the reasons.

Community
  • 1
  • 1
Vortex852456
  • 721
  • 6
  • 23
  • 1
    Part of the answer would be to use [Assembly Binding Redirect](https://msdn.microsoft.com/en-us/library/7wd6ex19%28v=vs.110%29.aspx)... – Peter Schneider May 11 '15 at 10:35
  • 1
    Package shared libraries into one or more NuGet packages that depend on each other and configure the dependency version numbers to ensure each package depends on other compatible packages. Release a new package when the dlls change. The clients will never see incompatible files. Upgrading a single package on the client will upgrade all other packages as well – Panagiotis Kanavos May 11 '15 at 10:40
  • 1
    check [Version agnostic dll reference](http://stackoverflow.com/questions/277817/compile-a-version-agnostic-dll-in-net) – Kurubaran May 11 '15 at 11:03

1 Answers1

1

What about assembly binding redirection - https://msdn.microsoft.com/en-us/library/433ysdt1(v=vs.110).aspx (one more msdn link) ?

You can specify in the config redirection to a new version, so it wont require recompile. But if signature of classes\methods that you are using will be changed - then it will throw an exception anyway.

ASP.Net MVC uses this approach to specify redirection to a new version of MVC:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>
Sergey Litvinov
  • 7,408
  • 5
  • 46
  • 67
  • For this to work, ensure assemblies are strongly typed and installed in GAC, that's where version helps in differentiating the files – Mrinal Kamboj May 11 '15 at 11:17
  • It shouldn't be present in GAC. MVC assemblies starting from 4.0 are installed by nuget. And `publicKeyToken` isn't required field in the `assemblyIdentity` node, but i'm not sure will it work without it – Sergey Litvinov May 11 '15 at 12:31
  • Thanks for your suggestion. I'm currently investigating it but it's not working yet. I edited the app.config file in a project with following tag: I compile it with the old dll and then I manually replace the older with the newer dll via file explorer. Reference error appears on exec. – Vortex852456 May 11 '15 at 13:51
  • 1
    I didn't work because I missed the attribute xmlns="urn:schemas-microsoft-com:asm.v1" on assemblyBinding. I will now try to make this config work for the whole directory without recompiling – Vortex852456 May 11 '15 at 14:21