Search code examples
c#.net-4.8

How to resolve a version issue between packages


We have an old framework application in need of package updates. The project has a dependency on System.ComponentModel.Annotations. The most recent version is "5.0.0.0".

This is the content of the project file:

<PropertyGroup>
    ...
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
    ...
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

One of the other packages, over which I have no control, uses version "4.2.0.0" of the annotations package. The auto generated binding redirects do not solve this. There are several questions about binding redirects, but none seem address my situation.

How do I modify my project file to make this work, or do I need something altogether different?


Solution

  • Adding the followning binding redirect to the app.config solves the problem:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    ...
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>