Dependent assembly version conflict & Binding redirects

pwojtowiczpwojtowicz USMember ✭✭

When building Android project (created by Xamarin.Forms) I am getting known warning:

Warning 5 Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Net.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.ServiceModel.Http" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.ServiceModel.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /></dependentAssembly></assemblyBinding>

So to solve it I've created app.config file in main project folder, added it to solution (Build Action: None, Copy to Output Directory: Do not copy).

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

But unfortunately the warning still appears. Do I need to do something more or do I have to do something different?

Posts

  • JohnHardmanJohnHardman GBUniversity mod

    @pwojtowicz - I encountered the same thing today, and also updated app.config . However, my understanding is that app.config is run-time configuration, whereas the warnings are being produced at build-time. So, whilst changing app.config makes what happens at run-time predictable, it doesn't actually resolve the build-time warnings. I haven't resolved this yet (I hit it at end of day) and am not working tomorrow, so will re-visit it later in the week. If you fix it before then, can you please post what you do, otherwise I will investigate and hopefully solve it later in the week.

    Thanks,

    John H.

  • pwojtowiczpwojtowicz USMember ✭✭
    edited May 2015

    You might be right :) and I don't think I will have any more info about it, cause I've read everything I could find about it and finished preparing app.config. But if you will manage to solve it somehow I will be very glad to know also the answer :)

  • JohnHardmanJohnHardman GBUniversity mod

    @pwojtowicz - I spent some time searching through the various bits and pieces that my solution is dependent upon. Using IL DASM, I checked the dependency hierarchy, looking at the Manifest for each assembly referenced.

    It turns out that some third-party bits that I use, such as LinqToTwitterPcl reference quite old versions of assemblies, whereas other bits reference newer versions. For example, LinqToTwitterPcl has the following in its manifest:

    .assembly extern System.Net.Http
    {
    .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
    .ver 1:5:0:0
    }

    So, the overall system is trying to use 1.5.0.0 of System.Net.Http AND elsewhere 4.0.0.0 . Unfortunately, that means that short of re-building LinqToTwitterPcl (if I had the source code, which I don't), or getting the author to re-build it, or hacking the manifest in the assembly itself (which would be very bad),, the options are probably:

    (1) Use app.config (as we have both already done), and ignore (or turn off) the warnings at build time
    (2) explicitly make your solution use the older dependency version. Of course, you may be using multiple third-party assemblies that each request a different version, so that latter solution isn't always possible. Or you may need a feature that is only in a newer one...

    So, I'm afraid to say (as I hate doing this), disabling the build-time warning (MSB3247) and then changing app.config to make what happens at run-time explicit, is probably as good as it gets.

    Note that after using IL DASM to check this, I discovered the brilliant AsmSpy utility, which can be downloaded from http://mikehadlow.blogspot.co.uk/2011/02/asmspy-little-tool-to-help-fix-assembly.html

    I definitely recommend getting hold of that tool - it saves a lot of time.

    It is also worth setting the "MSBuild project build output verbosity level" in Visual Studio to "Detailed", as this gives a much better indication of what the build process is actually doing.

    Regards,

    John H.

  • pwojtowiczpwojtowicz USMember ✭✭

    @JohnHardman - awesome research and analyse, thank you :)

    Regards,
    Piotr

Sign In or Register to comment.