0

I'm trying to implement the solution of the following earlier question and I don't want to hijack that question, so I'm posting a new one. I hope this is ok. Same DLLs two different versions

I have a project structure like the following

  • Client
    • Form1.cs
  • TiaOpennessV15_1
    • TiaOpenness.cs
    • V151
      • Siemens.Engineering.dll (15.1.0.0)
  • TiaOpennessV16
    • TiaOpenness.cs
    • V16
      • Siemens.Engineering.dll (16.0.0.0)

Both of the TiaOpenness-projects are using a dll-file called Siemens.Engineering, though they use the versions 15.1.0.0 and 16.0.0.0 respectively. I have put these dll-files in the seperate projects under the folders V151 and V16 respectively. I have referenced the different dll-files in each of the TiaOpenness-projects and set "Copy Local" to False.

In my client project (Windows Forms) I have the following App.config code.

App.config [Solved]

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Siemens.Engineering" publicKeyToken="d29ec89bac048f84" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0"/>
      <bindingRedirect oldVersion="15.1.0.1-16.0.0.0" newVersion="16.0.0.0"/>
      <codeBase version="15.1.0.0" href="V151\Siemens.Engineering.dll"/>
      <codeBase version="16.0.0.0" href="V16\Siemens.Engineering.dll"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

When I fire up the client, I can verify that the client is using the 16.0.0.0 version of the dll in both cases by running the code below.

private void FindInstancesButton_Click(object sender, EventArgs e)
{
  List<int> instances = new List<int>();

  using (Base core = new Base(new TiaOpennessV15_1.TiaOpenness()))
  {
    instances.AddRange(core.ListInstanceIds());
  }

  using (Base core = new Base(new TiaOpennessV16.TiaOpenness()))
  {
    instances.AddRange(core.ListInstanceIds());
  }
}

If I remove the App.config code from above, I get the following error.

System.IO.FileNotFoundException: 'Could not load file or assembly 'Siemens.Engineering, Version=16.0.0.0, Culture=neutral, PublicKeyToken=d29ec89bac048f84' or one of its dependencies. The system cannot find the file specified.'

Note that the same dialog is having an Inner Exception that states the version 15.1.0.0 instead of version 16.0.0.0, but with the same PublicKeyToken.

I have checked that both dll-files are moved to the folders V151 and V16 respectively in the bin/debug-folder. I don't know what else to do anymore... Any help is greatly appreciated!

EDIT 1 @KlausGütter: I want to be able to use my client to access both TiaOpenness-projects (class libraries) where each project should use its own version of the dlls. The different versions return different instance ids and I should have a set of two different integers in the instances-list in the FindInstancesButton_Click-function above.

What is happening right now is that both TiaOpenness-projects are using the same dll even though I am trying to use the different dlls.

EDIT 2 @KlausGütter: Thank you Klaus! It turned out that there were automatically a bindingRedirect inserted in to the config file after compilation. I didn't see the post you were linking before, but sure enough I had to insert my own bindingRedirects in to the config file and set the to false. After a rebuild of the solution, it worked great! Thank

I have edited the config code above to reflect the correct solution.

MotoX
  • 23
  • 4
  • 1
    Could you please make clearer what the desired behaviour is? Do you want to have *both* DLLs loaded into the process? – Klaus Gütter Jun 08 '20 at 13:28
  • @KlausGütter Hello Klaus. I have tried to explain more clearly in an edit what the desired behaviour is. Thank you! – MotoX Jun 08 '20 at 13:40
  • Did you have a look [here](https://stackoverflow.com/questions/42715564/using-2-different-versions-of-the-same-dll)? – Klaus Gütter Jun 08 '20 at 13:40
  • @KlausGütter Thank you very much Klaus, the link you posted had the correct answer! I'll post that as an answer here shortly. Oh man, I have spent 2 weeks on this before I turned to StackOverflow... Thanks a bunch, again! – MotoX Jun 08 '20 at 13:54

0 Answers0