Due to changes in a 3rd party library I am trying to use two different versions of the same DLL. There are any number of references for doing this, such as this, but they describe slightly different solutions for slightly different issues, and none seems to have the problem I an having.
The first issue I came across was that adding a reference to a second version of the DLL in Visual Studio 2022 would not work, failing with a error ("A reference to could not be added. A reference to the component 'TallComponents.PDF.Rasterizer' already exists in the project"). So instead I directly edited the csproj file as follows.
<Reference Include="TallComponents.PDF.Rasterizer, Version=4.0.39.0, Culture=neutral, PublicKeyToken=76bf2dedaa68ccb5, processorArchitecture=MSIL">
<HintPath>..\packages\TallComponents.PDFRasterizer4.4.0.39\lib\net46\TallComponents.PDF.Rasterizer.dll</HintPath>
<Aliases>TC4</Aliases>
</Reference>
<Reference Include="TallComponents.PDF.Rasterizer, Version=3.0.188.0, Culture=neutral, PublicKeyToken=76bf2dedaa68ccb5, processorArchitecture=MSIL">
<HintPath>bin\TC3\TallComponents.PDF.Rasterizer.dll</HintPath>
<Aliases>TC3</Aliases>
</Reference>
The code was then modified to use extern alias
to use the different functionality from the two versions of the library. The build was successful, but there was a MSB3243 warning.
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2401,5): warning MSB3243: No way to resolve conflict between "TallComponents.PDF.Rasterizer, Version=4.0.39.0, Culture=neutral, PublicKeyToken=76bf2dedaa68ccb5" and "TallComponents.PDF.Rasterizer, Version=3.0.188.0, Culture=neutral, PublicKeyToken=76bf2dedaa68ccb5". Choosing "TallComponents.PDF.Rasterizer, Version=4.0.39.0, Culture=neutral, PublicKeyToken=76bf2dedaa68ccb5" arbitrarily. 5> Consider app.config remapping of assembly "TallComponents.PDF.Rasterizer, Culture=neutral, PublicKeyToken=76bf2dedaa68ccb5" from Version "3.0.188.0" [C:\Dev\DelftRed\PL-1520_SlowFloorPlan\Plandroid\bin\TC3\TallComponents.PDF.Rasterizer.dll] to Version "4.0.39.0" [C:\Dev\DelftRed\PL-1520_SlowFloorPlan\packages\TallComponents.PDFRasterizer4.4.0.39\lib\net46\TallComponents.PDF.Rasterizer.dll] to solve conflict and get rid of warning.
The application ran and functionality based on version 4 of the library worked. Library version 3 functionality failed with a 'Method not found' error. The Modules panel in Visual Studio showed that only version 4 of the dll had been loaded.
There are also addition steps that are apparently required to make 2 versions of the same DLL work. In particualar, I have added the following dependentAssembly
element in the configuration/runtime/assemblyBinding
element of app.config and made sure that the DLLs are in the correct locations when being executed.
<dependentAssembly>
<assemblyIdentity name="TallComponents.PDF.Rasterizer" culture="neutral" publicKeyToken="76bf2dedaa68ccb5"/>
<codeBase version="3.0.188.0" href="TC3\TallComponents.PDF.Rasterizer.dll" />
<codeBase version="4.0.39.0" href="TallComponents.PDF.Rasterizer.dll" />
</dependentAssembly>
I'm looking for any clue to help make this work.
I don't know how you modified app.config exactly, there are 2 things I need to mention:
The dependentAssembly
element should be put in a configuration/runtime/assemblyBinding
element.
You need to uncheck the Auto-generate binding redirects
option in the project properties window, and delete the .exe.config
file in the output folder.