Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BindingRedirects not generated for a specific reference #2547

Open
AbhitejJohn opened this issue Sep 21, 2018 · 11 comments
Open

BindingRedirects not generated for a specific reference #2547

AbhitejJohn opened this issue Sep 21, 2018 · 11 comments
Assignees
Milestone

Comments

@AbhitejJohn
Copy link
Contributor

AbhitejJohn commented Sep 21, 2018

In the attached the solution, the AutoBindingRedirect isn't generating redirections for "System.Buffers" causing runtime failures.
Here is the dependency graph showing the disparity

  1. StreamJsonRpc 2.0.52-alpha -> Nerdbank.Streams 2.0.165-beta -> System.Buffers (>= 4.5.0)
  2. StreamJsonRpc 2.0.52-alpha -> System.Memory 4.5.1 -> System.Buffers (>= 4.4.0)

Now System.Memory 4.5.1 depends on 4.0.2.0 of System.Buffers.dll(which is in 4.4.0 version of the package) and since the version is resolved to 4.5.0 because of 1. that drops 4.0.3.0 in the artifacts folder.

This is a Class Library project targetting net461 and is on the new project system. Any suggestions for a workaround would be really useful.
BindingRedirectIssues.zip

@AbhitejJohn
Copy link
Contributor Author

Got this working with a manual specification in an app.config file for now.

@livarcocc
Copy link
Contributor

@dsplaisted can you take a look?

@livarcocc livarcocc added this to the Discussion milestone Sep 21, 2018
@dsplaisted
Copy link
Member

It looks like this is the same issue as here: https://github.com/dotnet/corefx/issues/32457

@mgravell
Copy link
Member

mgravell commented Oct 2, 2018

And certainly the same as https://github.com/dotnet/corefx/issues/32511 (ours is the dup, yours is older)

@AArnott
Copy link
Contributor

AArnott commented Jan 23, 2019

I just hit this myself. It took me a day to track down why things were failing since they were cross process and I was looking in all the wrong places. Please fix.

@AArnott
Copy link
Contributor

AArnott commented Jan 23, 2019

To clearly document the workaround, add an app.config file to your project with (at least) this content:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <!-- .NET SDK bug: we shouldn't have to explicitly set this.
          https://github.com/dotnet/sdk/issues/2547 -->
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

@jwfx
Copy link

jwfx commented Sep 23, 2020

@dsplaisted What is the state of this issue? Is this actively being worked on? Is there an official workaround or should everyone manage their binding redirects manually like shown above?

@dsplaisted
Copy link
Member

No, we're not actively looking at this or planning to fix this in the SDK. Generally the solution is to update to the fixed packages.

@NickCraver
Copy link
Member

For anyone else hitting this, I was also surprised to learn DLLs from NuGet packages aren't considered in ResolveAssemblyReferences by default. I had to explicitly enable this (very slight 1-2 sec perf impact at our ~500 project scale):

  <PropertyGroup>
    <FindDependenciesOfExternallyResolvedReferences>true</FindDependenciesOfExternallyResolvedReferences>
  </PropertyGroup>

...and then we're getting 17,000+ new redirects which we thought were being generated before. Basically: everything from NuGet. Cross-referencing back to several I've had to fix manually (encountered at runtime) the last few months, every single one was generated. This happens due to a skip in the reference table in MSBuild here: https://github.com/dotnet/msbuild/blob/b84faa7d0dfb42daedca5c244f73f0b07e1135d7/src/Tasks/AssemblyDependency/ReferenceTable.cs#L1692

cc @rainersigwald (I know I saw an identical issue in the MSBuild repo when digging into this, but been searching for half an hour and can't find it again).

@rainersigwald
Copy link
Member

That's interesting because common.targets should set that to true for you when you generate binding redirects:

https://github.com/dotnet/msbuild/blob/b84faa7d0dfb42daedca5c244f73f0b07e1135d7/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2349

@NickCraver
Copy link
Member

Update on the above: I was missing this due to .gitignore hosting VSCode search. In a port ages ago we actually had FindDependenciesOfExternallyResolvedReferences explicitly disabled in the repo. So indeed that target works just fine - leaving this comment here in case anyone stumbles across the same cause/behavior later!

ericdotnet added a commit to ericdotnet/Streams-Nerdbank-pro that referenced this issue May 13, 2024
This applies the fix/workaround required for dotnet/sdk#2547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants