Skip to content

Wrong Assembly Binding Redirect #595

Closed

Description

@dnauck

When Redirects option is on and you install the package Microsoft.Net.Http in a .NET 4.5 project you'll get a wrong binding redirect.

The package contains 2 extensions assemblies for .NET 4.5 and 3 for .NET 4.0.
During install on a .NET 4.5 project it will also add the redirect for the System.Net.Http assembly that is already in the GAC (and not in the package's 4.5 folder, only in the package's 4.0 folder).

Result is a assembly not found exception.

Activity

  1. forki commented on Feb 13, 2015

    @forki
    Member
  2. isaacabraham commented on Feb 13, 2015

    @isaacabraham
    Contributor

    @forki - I think that this is due to the way that we pick the appropriate assembly when there are multiple versions in the package - it was smartened a bit with a previous issue (can't remember which one) but looks like it needs some more work. I'll try to have a look at this one today or over weekend,

  3. isaacabraham commented on Feb 14, 2015

    @isaacabraham
    Contributor

    Just ran an empty net45 project with the single paket dependency Microsoft.Net.Http. I got the following binding redirects: -

        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>

    paket.lock is as follows: -

        Microsoft.Bcl (1.1.9)
          Microsoft.Bcl.Build (>= 1.0.14)
        Microsoft.Bcl.Build (1.0.21)
        Microsoft.Net.Http (2.2.28)
          Microsoft.Bcl (>= 1.1.9)
          Microsoft.Bcl.Build (>= 1.0.14)
        System.Net.Http (2.0.20505.0)
          Microsoft.Net.Http (>= 2.0.20505.0)
    

    The only assemblies that are referenced in the project, are: -

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll
    C:\Users\Isaac\Source\Repos\PacketTest\packages\Microsoft.Net.Http\lib\net45\System.Net.Http.Extensions.dll
    C:\Users\Isaac\Source\Repos\PacketTest\packages\Microsoft.Net.Http\lib\net45\System.Net.Http.Primitives.dll
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.WebRequest.dll
    

    In main _ I called:

    let x = System.Net.Http.HttpClient().GetStringAsync("http://www.bbc.co.uk") |> Async.AwaitTask |> Async.RunSynchronously
    

    which worked fine. So I can't actually reproduce the issue - can you give some more details on how to repro it?

    What I've noticed is: -

    1. As you say, System.Net.Http does not exist in the net45 folder, only in the net40, yet we still get a binding redirect for System.Net.Http. This to me seems like it shouldn't be there as it's probably only required for a different framework. /cc: @forki does this mean that we need to start having conditional binding redirects?
    2. I noticed an ensureRedirects.xml file in the package - no idea what that's doing there or if it has some special meaning for nuget.
  4. dnauck commented on Feb 16, 2015

    @dnauck
    ContributorAuthor

    Hello,

    this is the problem:

                <dependentAssembly>
                    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
                </dependentAssembly>

    There is no version 2.2.28.0, in .NET 4.5 there is version 4.0.0.0 in the GAC.

    The resulting exception:

    System.IO.FileNotFoundException was unhandled by user code
      HResult=-2147024894
      Message=Could not load file or assembly 'System.Net.Http, Version=2.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
      Source=Neo4jClient
      FileName=System.Net.Http, Version=2.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions