解压缩抛出“无法正确加载基础压缩例程”

尝试使用以下代码在Win10移动(UWP)上解压缩文件

using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read)) { ZipArchiveEntry entry = archive.Entries.First(); using (Stream reader = entry.Open()) { 

在entry.Open()抛出以下错误。 “无法正确加载底层压缩例程。”

内在的例外

“无法加载DLL’clrcompression.dll’:找不到指定的模块。(HRESULTexception:0x8007007E)”

重要提示:

  • entry.Open()在win10桌面上工作正常但在Win10移动版上没有工作,具有相同的项目(UWP)
  • 使用Win10移动版10.0.14393.576。 (Lumia 650)
  • UWP项目的目标版本是10.0 BUILD 14393
  • 对桌面和移动版本使用相同的文件。
  • 该文件在后端创建一个简单的文件

using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create,true))

  • 我正在使用Xamarin表格(我不认为这是相关的)

问题:有人经历过同样的例外吗? 它的根本原因是什么? 有哪些可用的解决方法? (我需要文件压缩跨平台)

更新:我按要求创建了简单的测试项目(感谢您查看)。

解压缩在测试项目中工作,但它正在加载一个不同的模块。 Debug / Modules窗口指出exception抛出项目使用System.IO.Compression.dll 4.06.24705.1,工作项目使用1.00.24301.1。

我上传了两个project.lock.json文件以进行比较https://1drv.ms/f/s!AqROiejT4oI3lL1q1tu3iJcfA2tKyg 。

根据你上传的“project.lock.json”,我认为这里的问题可能与System.IO.Compression 4.3.0包有关 。

在exception抛出项目中,您可以发现它使用“System.IO.Compression 4.3.0”,如下所示:

 "runtime.native.System.IO.Compression/4.3.0": { "type": "package", "dependencies": { "Microsoft.NETCore.Platforms": "1.1.0", "Microsoft.NETCore.Targets": "1.1.0" }, "compile": { "lib/netstandard1.0/_._": {} }, "runtime": { "lib/netstandard1.0/_._": {} } }, ... "System.IO.Compression/4.3.0": { "type": "package", "dependencies": { "System.Buffers": "4.3.0", "System.Collections": "4.3.0", "System.Diagnostics.Debug": "4.3.0", "System.IO": "4.3.0", "System.Resources.ResourceManager": "4.3.0", "System.Runtime": "4.3.0", "System.Runtime.Extensions": "4.3.0", "System.Runtime.Handles": "4.3.0", "System.Runtime.InteropServices": "4.3.0", "System.Text.Encoding": "4.3.0", "System.Threading": "4.3.0", "System.Threading.Tasks": "4.3.0", "runtime.native.System.IO.Compression": "4.3.0" }, ... 

在工作项目中,它使用“System.IO.Compression 4.1.1”:

 "runtime.native.System.IO.Compression/4.1.0": { "type": "package", "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1", "Microsoft.NETCore.Targets": "1.0.1" }, "compile": { "lib/netstandard1.0/_._": {} }, "runtime": { "lib/netstandard1.0/_._": {} } }, ... "System.IO.Compression/4.1.1": { "type": "package", "dependencies": { "System.Collections": "4.0.11", "System.Diagnostics.Debug": "4.0.11", "System.IO": "4.1.0", "System.Resources.ResourceManager": "4.0.1", "System.Runtime": "4.1.0", "System.Runtime.Extensions": "4.1.0", "System.Runtime.Handles": "4.0.1", "System.Runtime.InteropServices": "4.1.0", "System.Text.Encoding": "4.0.11", "System.Threading": "4.0.11", "System.Threading.Tasks": "4.0.11", "runtime.native.System.IO.Compression": "4.1.0" }, ... 

看来System.IO.Compression 4.3.0包暂时不能在UWP项目中使用。 目前最新的稳定版“Microsoft.NETCore.UniversalWindowsPlatform”包使用“System.IO.Compression 4.1.1”包。 您应该能够通过在其中添加System.IO.Compression 4.3.0软件包来重现您在工作项目中的问题,如下所示:

 { "dependencies": { "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", "System.IO.Compression": "4.3.0" }, "frameworks": { "uap10.0": { } }, "runtimes": { "win10-arm": { }, "win10-arm-aot": { }, "win10-x86": { }, "win10-x86-aot": { }, "win10-x64": { }, "win10-x64-aot": { } } } 

因此,为了解决这个问题,我建议您检查项目的参考,并确保没有“System.IO.Compression 4.3.0”软件包。 如果确实需要使用“System.IO.Compression”包,可以尝试将其降级为“4.1.1”。

我找到了根本原因。 正如Jay Zuo所说,问题是在project.lock.json中以某种方式引用了“System.IO.Compression 4.3.0”。

我没有直接在任何project.json文件中引用它。 我通过.NETSTANDARD1.1项目间接引用它,引用了“NETStandard.Library”:“1.6.1”。

通过使用nuget.org,我使用较旧的System.IO.Compression 4.1.1搜索了“NETStandard.Library”版本,即“NETStandard.Library”1.6.0。

使用“NETStandard.Library”1.6.0。 在.NETSTANDARD 1.1项目中修复了解压缩错误。

我上传了一个示例解决方案来重现错误。 https://1drv.ms/f/s!AqROiejT4oI3lMMc_jWogCQy36awrA

修复我的是将其添加到.csproj文件中的第一个PropertyGroup

 1.6.0 

Visual Studio通常隐式地为.NET Standard项目提供1.6.1,其中包含有问题的System.IO.Compression 4.3.0。 该指令告诉它取下1.6.0,这取决于System.IO.Compression 4.1.1(适用于Windows Phone)。

只要确保你没有另一个引入4.3.0的NuGet引用。 System.IO.Compression.dll的正确文件版本是1.0.24301.1,而损坏的文件版本是4.6.xxxx。