Project deployment, how to set assemblyBinding properly? or there is another way?

0

we have deployment server with Newtonsoft.Json ver 8.0.3 already there.

I build an app (ConsoleApp) that becomes a service. In my ConsoleApp I reference Newtonsoft.Json ver 11.0.0.

My app references other projects that also use different versions of Newtonsoft.Json.

When we deploy the app, we only copy the exe and config to deployment server. How to make sure our app will not fail because of incompatible versions of Newtonsoft.Json?

I tried to set runtime section to support assemblyBinding:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

What do I need to change in this section to make my code work?

Note: Newtonsoft.Json 8.0.3 is already on the server. We cannot overwrite it, since its a part of installation of another product.

My ConsoleApp references other projects that use Newtonsoft.Json 7.0.1, 10.0.5 and 11.0.0. When I build and copy exe & config over to deployment folder, the app complains:

Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Note also, if I change bindingRedirect property in Visual Studio and compile, it will set it back to what it was.

What is the best approach to resolve this problem?

Thank you.

visual-studio-2017
json.net
app-config
asked on Stack Overflow Jul 23, 2018 by monstro

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0