1

I have a C# Class Library (Project A) which needs Newtonsoft.Json DLL version 10.

But then I have another C# Class Library (Project B) which needs Newtonsoft.Json DLL version 6.

I cannot upgrade project B to use 10 because there are too many breaking changes.

Is it possible to have both versions exist together?

My issue is Project A has a Google.Apis dependency which is what has the dependency on Newtonsoft.Json DLL, so I cannot simply rename the DLL and have them both in the same directory.

I've seen other solutions mentioning an App.Config file but since this is a class library it doesn't have a config file.

Is there anyway to do this?

mocode10
  • 589
  • 1
  • 6
  • 23
  • Look up the `` config file element: https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element. Hopefully the newer version is backwards compatible and strongly named with the same token. If so, it should fix your issue. You say you have "too many breaking changes". If so, then you are probably in a bad way. Does NewtonSoft provide any advice? We've regularly papered over JSON.net version issues like this before, but not that far back. – Flydog57 Nov 05 '18 at 20:32
  • Will the bindingRedirect be of any use in this case as class libraries do not have an app.config file? – mocode10 Nov 05 '18 at 21:02
  • No, you put the `` on the consumer of your two class libraries. If there are "here are too many breaking changes", it probably doesn't matter. @Cookinski's suggestion may be the only solution. Or check NewtonSoft's support site. – Flydog57 Nov 05 '18 at 21:10
  • Does this answer your question? [Using multiple versions of the same DLL](https://stackoverflow.com/questions/5916855/using-multiple-versions-of-the-same-dll) – malat Sep 21 '22 at 06:57

1 Answers1

1

Maybe this could help:

Use AppDomain.CurrentDomain.AssemblyResolve build event and load the specific dll.

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

public static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    //debug and check the name
    if (args.Name == "MyDllName")
        return Assembly.LoadFrom("c:\\pathdll\midllv1.dll")
    else if(args.Name ="MyDllName2")
        return Assembly.LoadFrom("c:\\pathdll\midllv2.dll");
    else
        return Assembly.LoadFrom("");
}
  • I have been searching for an answer to dll hell with Newtonsoft.json. THIS solution has finally resolved that growing problem at my employer. THANK YOU. – Jonathan Hansen Jun 08 '20 at 15:56