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

SharpCompress 0.28.1 depends on System.Buffers 4.4.0, but NuGet transitively depends on 4.5.1 #591

Closed
schlotter opened this issue Apr 13, 2021 · 5 comments
Labels

Comments

@schlotter
Copy link

Bug description

Using SharpCompress 0.28.1 in a .NET 4.6.2 unit test project I get the following 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 SharpCompress.Utility.Skip(Stream source)
   at SharpCompress.Common.EntryStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at SharpCompress.Readers.AbstractReader`2.Write(Stream writeStream)
   at SharpCompress.Readers.AbstractReader`2.WriteEntryTo(Stream writableStream)
   at SharpCompress.Readers.IReaderExtensions.<>c__DisplayClass4_0.<WriteEntryToFile>b__0(String x, FileMode fm)
   at SharpCompress.Common.ExtractionMethods.WriteEntryToFile(IEntry entry, String destinationFileName, ExtractionOptions options, Action`2 openAndWrite)
   at SharpCompress.Readers.IReaderExtensions.WriteEntryToFile(IReader reader, String destinationFileName, ExtractionOptions options)
   at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write)
   at SharpCompress.Readers.IReaderExtensions.WriteEntryToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options)
   at ...

Analysis

Build output

The detailed MSBuild output of building the test project shows:

2>  Unified primary reference "System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
2>      Using this version instead of original version "4.0.2.0" in "C:\Users\xxx\.nuget\packages\sharpcompress\0.28.1\lib\netstandard2.0\SharpCompress.dll" because AutoUnify is 'true'.
2>      Resolved file path is "C:\Users\xxx\.nuget\packages\system.buffers\4.5.1\ref\net45\System.Buffers.dll".
2>      Reference found at search path location "{RawFileName}".
2>      Found related file "C:\Users\xxx\.nuget\packages\system.buffers\4.5.1\ref\net45\System.Buffers.xml".
2>      This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".
2>      The ImageRuntimeVersion for this reference is "v4.0.30319".

Dependency of SharpCompress 0.28.1 (.NET Standard 2.0) assembly

Disassembling the SharpCompress 0.28.1 assembly with ildasm shows that it indeed references "System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51":

.assembly extern System.Buffers
{
  .publickeytoken = (CC 7B 13 FF CD 2D DD 51 )                         // .{...-.Q
  .ver 4:0:2:0
}

Dependency of SharpCompress 0.28.1 NuGet package

The SharpCompress 0.28.1 NuGet package depends on System.Buffers in the following way:
SharpCompress 0.28.1 → >= System.Memory 4.5.4 → >= System.Buffers 4.5.1

Signature of System.Buffers 4.4.0

Disassembling System.Buffers 4.4.0 NuGet package with ildasm, we get the following signature:

.assembly System.Buffers
{
  // snip
  .ver 4:0:2:0
}

Signature of System.Buffers 4.5.1

Disassembling System.Buffers 4.5.1 NuGet package with ildasm, we get the following signature:

.assembly System.Buffers
{
  // snip
  .ver 4:0:3:0
}

Conclusion

The .NET Standard 2.0 assembly of SharpCompress.dll which is contained in the SharpCompress 0.28.1 NuGet package depends on System.Buffers.dll which is contained in the System.Buffers 4.4.0 NuGet package (assembly version 4.0.2.0).

This creates a version conflict because the SharpCompress 0.28.1 NuGet package transitively depends on the System.Buffers 4.5.1 NuGet package (assembly version 4.0.3.0).

Workaround

I was able to work around this issue by forcing the System.Buffers NuGet version to 4.4.0:

<PackageReference Include="SharpCompress" Version="0.28.1" />
<PackageReference Include="System.Buffers" Version="[4.4.0]" />

The drawback is that it generates the following warning:

NU1605: Detected package downgrade: System.Buffers from 4.5.1 to 4.4.0. Reference the package directly from the project to select a different version. 
 MyProject.UnitTests -> SharpCompress 0.28.1 -> System.Memory 4.5.4 -> System.Buffers (>= 4.5.1) 
 MyProject.UnitTests -> System.Buffers (= 4.4.0)
@quessith
Copy link

Thanks i couldnt figure out the issue untill i found your post!
Cheers and thanks for that!

@schlotter
Copy link
Author

I think this is the same bug as dotnet/runtime#1830.

@adamhathcock
Copy link
Owner

Thanks for this information. I can put a specific locked version against the .NET Standard 2.0 (and possibly 2.1) but unsure what versions to use.

@adamhathcock
Copy link
Owner

Downgrading to System.Memory 4.5.3 will be System.Buffers 4.4.0:
#592

@adamhathcock
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants