8

I have an c# application with two libraries ( moon-apns, tweetsharp ) .. Each library has a reference for newtonsoft.json.dll but different versions ... My app build successfully but one library works fine and the other one throws an exception ( can't find the dll file ).

I think that when i build only one version goes to the bin folder, but i don't know what to do.

Thanks in advance.

leppie
  • 115,091
  • 17
  • 196
  • 297
Islam Ahmed
  • 539
  • 1
  • 5
  • 17
  • 1
    If both libraries were built with "Specific Version" required I am not sure what can be done. I assume you have no access to the two libraries correct? – JeremyK Mar 29 '13 at 13:19
  • 2
    I think you can use this post to solve it (I think): http://stackoverflow.com/questions/8188191/how-to-manage-version-dependencies-in-a-c-net-project – Rikon Mar 29 '13 at 13:24
  • Are you sure those libraries need different versions of newtonsoft, or can you just put in a single version and let them both use that (or rebuild one/both to use a single version)? – ssube Mar 29 '13 at 13:33
  • Both moon-apns and tweetsharp is opensource projects available on github. Download sources, add to your solution both projects. Set it depends from the same newtonsoft.json.dll and add reference in your own code to this projects instead of precompilled dlls. – Tommi Mar 29 '13 at 13:41
  • @jeremyk i have access to source code of libraries ... But don't what to do to make each library deal with specific version of dll – Islam Ahmed Mar 29 '13 at 14:40
  • Try setting the "Specific Version" to false on the reference to newtonsoft in the other libraries. – JeremyK Mar 29 '13 at 15:08
  • 1
    Do binding redirects work for projects with specific version set? Don't recall offhand, but might be worth a try. – JerKimball Mar 29 '13 at 17:09
  • 1
    @JerKimball Yes, binding redirects should work. – Rytmis Mar 29 '13 at 19:18

2 Answers2

4

You can force both libraries to reference the same version by using Assembly Binding Redirects in your app.config or web.config. Obviously this only works as long as the library versions are compatible.

Rytmis
  • 31,467
  • 8
  • 60
  • 69
  • You might also be able to handle the [`AppDomain.AssemblyResolve` event](https://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(v=vs.110).aspx). [See here for an example](http://www.aboutmycode.com/net-framework/assemblyresolve-event-tips/). – Uwe Keim Jan 25 '16 at 05:50
2

Since you stated you have access to the source of the two libraries:

In both projects, set the reference to newtonsoft to not required Specific Version. Rebuild those projects.

Now, when you build your main project, the two libraries should be ok with the same version of the newtonsoft DLL as long as there is no compatibility issues

JeremyK
  • 1,075
  • 1
  • 22
  • 45