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>..packagesTallComponents.PDFRasterizer4.4.0.39libnet46TallComponents.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>binTC3TallComponents.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 FilesMicrosoft Visual Studio2022CommunityMSBuildCurrentBinamd64Microsoft.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:DevDelftRedPL-1520_SlowFloorPlanPlandroidbinTC3TallComponents.PDF.Rasterizer.dll] to Version "4.0.39.0" [C:DevDelftRedPL-1520_SlowFloorPlanpackagesTallComponents.PDFRasterizer4.4.0.39libnet46TallComponents.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 modified app.config as follows 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.108.0" href="TC3TallComponents.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.
2
Answers
You can try to create a new project that will reference your problem library, and create the same structure that is in the problem library, the same methods and properties except namespace. And inside them just call the methods from the problem library. For example
I think it will 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 aconfiguration/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.