5

I'm facing the following problem (or a challenge, if one prefers to call it this way): in our C# desktop application we have two vendors of additional data processing libraries (both developed with MATLAB, different versions though). Each of the libraries depends on MathWorks' MWArray.dll, each needs a different version of.

Let me show you a sketch of the situation: enter image description here

What I know for sure (tested) is:

  • both libraries can be called individually without any problems
  • two versions of MRC (Matlab Runtime Compiler) can coexist and don't cause interference problems (see above)
  • a library compiled against older version of MWArray.dll cannot be used with a newer version

What I've already tried:

    <runtime>
        <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">  
          <dependentassembly>
            <assemblyidentity name="MWArray" publickeytoken="e1d84a0da19db86f" />
            <bindingredirect oldVersion="0.0.0.0-2.17.0.0" newVersion="2.17.0.0" />
            <codebase version="2.17.0.0" href="C:\Windows\Microsoft.NET\assembly\GAC_MSIL\MWArray\v4.0_2.17.0.0__e1d84a0da19db86f\MWArray.dll" />
            <codebase version="2.18.0.0" href="C:\Windows\Microsoft.NET\assembly\GAC_MSIL\MWArray\v4.0_2.18.0.0__e1d84a0da19db86f\MWArray.dll" />
          </dependentassembly>
        </assemblybinding>
    </runtime>
  • I've placed both versions of MWArray.dll in "Resources" path (one named MWArray.2.17.0.0.dll, the other MWArray.2.18.0.0.dll), added both as references, edited App.config accordingly. Now Library1 crashes complaining it cannot initialise MWArray. Which is logical since it cannot find MWArray.dll since only some MWArray.x.x.x.x.dll are available.


I will appreciate any hints or tips on handling this issue, a working solution would, of course, be the best.

Again - it's not my code that needs to reach MWArray, it's the vendor's code I'm referencing.

Mike
  • 1,225
  • 10
  • 21
  • 1
    Use binding redirects with the `` element to redirect each version to their own directory. For example ``. I've done this during the [Umbraco/Log4Net public key token hassle](https://our.umbraco.com/forum/developers/extending-umbraco/45996-log4net-public-token-issues-could-not-load-file-or-assembly), and it worked. – CodeCaster May 20 '19 at 13:59
  • 1
    @CodeCaster - I've tried to use your suggestion, unfortunately it's not working. Furhtermore, the question you appointed as the duplicate handles the problem of 1st order dependency, mine is 2nd order dependency. – Mike May 20 '19 at 15:09
  • Are you certain of this statement? *a library compiled against older version of MWArray.dll cannot be used with a newer version*. They aren't even different major versions. If you are correct, and they really broke backward compatibility, they have made your life very difficult. You may end up having to load the libraries in separate application domains. – John Wu May 20 '19 at 17:02
  • @JohnWu - if it was not true I wouldn't have posted this question. I've tried that in the first place and I get errors. Any examples on how to load the libraries in separate application domains? – Mike May 20 '19 at 20:35
  • @Mike, I wasn't sure if you meant "I conclude that a library compiled against the older version won't work because I can't get it to work" versus "the publisher of the libraries has stated that that 2.18.0 breaks backward compatibility" or "the interfaces and behavior have changed significantly so I need both versions." That is why I ask if you're certain; it's highly unusual to nuke your product's compatibility in that way. [Load different version of assembly into separate AppDomain](https://stackoverflow.com/questions/21941474/load-different-version-of-assembly-into-separate-appdomain) – John Wu May 20 '19 at 21:14
  • @JohnWu - MathWorks states that MCR is version specific: https://nl.mathworks.com/matlabcentral/answers/78569-backward-compatibility-of-mcr And for what I have tried I am certain. – Mike May 21 '19 at 07:30

1 Answers1

0

Have you tried dependency redirection? Here's piece of code from Web|App.config:

<dependentAssembly>
    <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.3.1" newVersion="4.0.3.1" />
</dependentAssembly>
Fka
  • 6,044
  • 5
  • 42
  • 60