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

System.Runtime.CompilerServices.Unsafe binding redirect missing when also referencing System.IO.Pipelines #28789

Closed
AArnott opened this issue Feb 26, 2019 · 10 comments

Comments

@AArnott
Copy link
Contributor

AArnott commented Feb 26, 2019

When referencing the latest System.IO.Pipelines and System.Runtime.CompilerServices.Unsafe packages from a net46 application, the binding redirects required at runtime are not generated automatically, resulting in runtime failure:

Repro

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="system.IO.Pipelines" Version="4.5.3" />
    <!--<PackageReference Include="System.Memory" Version="4.5.2" />-->
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
  </ItemGroup>
</Project>
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

class Program
{
    static void Main(string[] args)
    {
        byte[] buffer = new byte[4];
        int value = Unsafe.ReadUnaligned<int>(ref MemoryMarshal.GetReference(buffer.AsSpan()));
    }
}

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at System.Span`1..ctor(T[] array)
at System.MemoryExtensions.AsSpan[T](T[] array)
at Program.Main(String[] args)

When uncommenting the System.Memory PackageReference in the project file in the above repro, the problem goes away. I believe this has already been fixed in the latest System.Memory package. The problem is that the latest System.IO.Pipelines package refers to an older version of System.Memory that does not include the fix.

Similar to #27492

@davidfowl
Copy link
Member

cc @ericstj any ideas?

@ericstj
Copy link
Member

ericstj commented Mar 14, 2019

When a package is update to fix a servicing issue we don't update every package that references it. What happens if you reference the latest pre-release package out of master?

@davidfowl
Copy link
Member

Is there anything to do here?

@ericstj
Copy link
Member

ericstj commented Jun 10, 2019

It may have been fixed in with the latest baselining that @joperezr did in master. @AArnott does it still repro in the latest packages?

@AArnott
Copy link
Contributor Author

AArnott commented Jun 10, 2019

The versions in the repro are still the latest (stable) packages. Did you want me to test the preview packages that have been pushed to nuget?

@AArnott
Copy link
Contributor Author

AArnott commented Jun 10, 2019

Using the latest preview packages, the problem still repros.

    <PackageReference Include="system.IO.Pipelines" Version="4.6.0-preview5.19224.8" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0-preview6.19259.10" />

@ericstj
Copy link
Member

ericstj commented Jun 10, 2019

That's not latest. Why are you not using a preview6 build for pipelines? Looks like Nuget.org only has preview 5. Can you grab the latest off of https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json.

@ericstj
Copy link
Member

ericstj commented Jun 10, 2019

Worked for me when referencing

    <PackageReference Include="System.IO.Pipelines" Version="4.6.0-preview7.19310.3" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0-preview7.19310.3" />

@AArnott please give a try and close if you're fixed.

@ericstj
Copy link
Member

ericstj commented Jun 10, 2019

Or if you prefer Preview6 (upcoming release):

    <PackageReference Include="System.IO.Pipelines" Version="4.6.0-preview6.19303.8" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0-preview6.19303.8" />

I found that the 4.6.0-preview6.19259.10 version of Unsafe was a one-off build out of master that isn't a complete set of packages.

@AArnott
Copy link
Contributor Author

AArnott commented Jun 10, 2019

Yes, with 4.6.0-preview6.19303.8 it works. Thanks.

@AArnott AArnott closed this as completed Jun 10, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 14, 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

4 participants