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

Invalid assemblyBinding redirects lead to FileLoadException when using System.Buffers in certain scenario #26600

Closed
adamsitnik opened this issue Jun 25, 2018 · 3 comments

Comments

@adamsitnik
Copy link
Member

This bug has been found by @NickCraver and @mgravell during port of StackOverflow to .NET Core

The repo can be found here: https://github.com/adamsitnik/Pipelines.Sockets.Unofficial/blob/repro/repro/Repro/Program.cs

How to reproduce:

git clone https://github.com/adamsitnik/Pipelines.Sockets.Unofficial.git
cd Pipelines.Sockets.Unofficial
git checkout 907cc75e491b0eb7abf2ea39dc08b44321e14692
cd repro/Repro
dotnet run -c Release -f net46

Output:

PS C:\Projects\Pipelines.Sockets.Unofficial\repro\Repro> dotnet run -c Release -f net46

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at System.Buffers.ArrayMemoryPool`1.ArrayMemoryPoolBuffer..ctor(Int32 size)
   at System.Buffers.ArrayMemoryPool`1.Rent(Int32 minimumBufferSize)
   at System.IO.Pipelines.Pipe.AllocateWriteHeadUnsynchronized(Int32 sizeHint)
   at System.IO.Pipelines.Pipe.GetMemory(Int32 sizeHint)
   at System.IO.Pipelines.Pipe.DefaultPipeWriter.GetSpan(Int32 sizeHint)
   at Pipelines.Sockets.Unofficial.PipeTextWriter.WriteImpl(PipeWriter writer, ReadOnlySpan`1 chars, Encoding encoding, Encoder encoder)
   at Pipelines.Sockets.Unofficial.PipeTextWriter.Write(PipeWriter writer, ReadOnlySpan`1 value, Encoding encoding)
   at Pipelines.Sockets.Unofficial.Tests.PingPongTests.<WritePing>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Pipelines.Sockets.Unofficial.Tests.PingPongTests.<PingPong>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Pipelines.Sockets.Unofficial.Tests.PingPongTests.<Basic_Pipelines_PingPong>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Repro.Program.Main(String[] args)

Some more details:

  1. Project Pipelines.Sockets.Unofficial targets netstandard2.0;netcoreapp2.0;netcoreapp2.1;net46 and references System.IO.Pipelines and System.Buffers both Version 4.5.0. The project is signed.
  2. Project Pipelines.Sockets.Unofficial.Tests references Pipelines.Sockets.Unofficial and targets net46;netcoreapp2.0
  3. Project Benchmarks references Pipelines.Sockets.Unofficial.Tests and targets net46;netcoreapp2.1
  4. Project Repro references Benchmarks and targets net46;netcoreapp2.1

I have tried to produce simpler repro case, but I have failed. It works fine for .NET Core 2.1

IMHO VS/dotnet cli for some reason fails to generate the assembly binding redirects for System.Buffers for .NET 4.6.

I have provided a workaround mgravell/Pipelines.Sockets.Unofficial#4

I don't know which repository is the best to report this bug, I decided to report it where System.Buffers belong.

knocte referenced this issue in nblockchain/geewallet Sep 29, 2018
knocte referenced this issue in diginex/gwallet Sep 29, 2018
Hopefully this works as a workaround of the following issue:
https://github.com/dotnet/corefx/issues/30642

(Which started happening after upgrading NBitcoin, which
implied an upgrade of the System.Buffers dependency.)
knocte referenced this issue in nblockchain/geewallet Oct 3, 2018
This lets us drop the CryptSharpOfficial dependency
(thanks to MetacoSA/NBitcoin#444),
but requires us to replace NBitcoin.Litecoin with the new
NBitcoin.Altcoins.

CryptSharpOfficial dep has some nuget problems when restoring
in the frontend branch, plus I trust it less than NBitcoin.

NOTE: the binding redirect is needed because otherwise we
would see exceptions similar to the one mentioned here[0].

(This was done already in [1], but we had to revert it [2]
because I found a problem with NBitcoin+.NETStandard that
I fixed in this other PR [3].)

[0] https://github.com/dotnet/corefx/issues/30642
[1] 6cf138c
[2] c569bb2
[3] MetacoSA/NBitcoin#545
@joshfree
Copy link
Member

IMHO VS/dotnet cli for some reason fails to generate the assembly binding redirects for System.Buffers for .NET 4.6.

@ericstj could you comment on this issue while @joperezr is out?

@ericstj
Copy link
Member

ericstj commented Feb 27, 2019

This is a duplicate of https://github.com/dotnet/corefx/issues/32457.

I tried out the repro and it is fixed with the latest System.IO.PipeLines package: 4.5.3.

@ericstj ericstj closed this as completed Feb 27, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants