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

Closed
opened 2026-01-29 22:12:23 +00:00 by claunia · 5 comments
Owner

Originally created by @schlotter on GitHub (Apr 13, 2021).

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)
Originally created by @schlotter on GitHub (Apr 13, 2021). # 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: ``` xml <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) ```
claunia added the bug label 2026-01-29 22:12:23 +00:00
Author
Owner

@quessith commented on GitHub (Apr 15, 2021):

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

@quessith commented on GitHub (Apr 15, 2021): Thanks i couldnt figure out the issue untill i found your post! Cheers and thanks for that!
Author
Owner

@schlotter commented on GitHub (Apr 22, 2021):

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

@schlotter commented on GitHub (Apr 22, 2021): I think this is the same bug as dotnet/runtime#1830.
Author
Owner

@adamhathcock commented on GitHub (Apr 24, 2021):

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 commented on GitHub (Apr 24, 2021): 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.
Author
Owner

@adamhathcock commented on GitHub (Apr 24, 2021):

Downgrading to System.Memory 4.5.3 will be System.Buffers 4.4.0:
https://github.com/adamhathcock/sharpcompress/pull/592

@adamhathcock commented on GitHub (Apr 24, 2021): Downgrading to System.Memory 4.5.3 will be System.Buffers 4.4.0: https://github.com/adamhathcock/sharpcompress/pull/592
Author
Owner

@adamhathcock commented on GitHub (Jun 4, 2021):

Released https://www.nuget.org/packages/SharpCompress/0.28.3

@adamhathcock commented on GitHub (Jun 4, 2021): Released https://www.nuget.org/packages/SharpCompress/0.28.3
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#456