2

I need to use Nest 1.9.2 (which is hardwired to Newtonsoft.Json 9.x) and Puppeteer (requires Newtonsoft.Json 10.x or higher) in the same project.

Nest actually uses a Newtonsoft.Json feature that was removed in 10.x, so I can't just force it.

So, is there a way to use multiple versions of Newtonsoft.Json in the same project?

AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • Possible duplicate of [Using multiple versions of the same DLL](https://stackoverflow.com/a/5916866/1260204) – Igor Feb 26 '19 at 19:12
  • 1
    Possible duplicate of [Using multiple versions of the same DLL](https://stackoverflow.com/questions/5916855/using-multiple-versions-of-the-same-dll) – Kit Feb 26 '19 at 19:15

1 Answers1

3

If you talk about referring two versions DLL in one single project, there is a workaround. You can refer both nuget packages and then in your driver application (console or web or winform) configuration file, you can add binding redirect to use only one version - as long as your dependencies do not break.

If you talk about using multiple version DLLs in the same application then there are 3 ways to do this as specified in this article. Although this article is for Kentico, it should be able to help you to resolve your query.

1. Install assembly in GAC

2. Custom resolver logic as specified in this question

Copying code from that answer to here for ready reference:

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

    static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (/*some condition*/)
            return Assembly.LoadFrom("DifferentDllFolder\\differentVersion.dll");
        else
            return Assembly.LoadFrom("");
    }

3. Using CodeBase in your application's configuration file

In web.config, you can specify assembly binding redirects.

You can create two folders one for each version and then tell your application to refer that where particular version of a DLL resides.

<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
         <dependentAssembly>  
            <assemblyIdentity name="myAssembly"  
                              publicKeyToken="32ab4ba45e0a69a1"  
                              culture="neutral" />  

            <codeBase version="1.0.0.0"  
                      href="v1\myAssembly.dll"/>  


            <codeBase version="2.0.0.0"  
                      href="v2\myAssembly.dll"/>  
         </dependentAssembly>  
      </assemblyBinding>  
   </runtime>  
</configuration>  

There is another way specified at this MSDN blog.

Hope this helps you.

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37