解压会抛出“无法正确加载底层压缩例程" [英] Unzipping throws an "The underlying compression routine could not be loaded correctly"

查看:27
本文介绍了解压会抛出“无法正确加载底层压缩例程"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to unzip a file on Win10 mobile (UWP) with the following code

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

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

throws at entry.Open() the following error. "The underlying compression routine could not be loaded correctly."

内部异常

无法加载 DLL 'clrcompression.dll':找不到指定的模块.(来自 HRESULT 的异常:0x8007007E)"

"Unable to load DLL 'clrcompression.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

重要提示:

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

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

  • 我正在使用 Xamarin 表单(我认为这无关紧要)

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

Questions: Has somebody experienced the same exception? What is the root cause of it? What are available workarounds? (I need the file compressed cross platform)

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

UPDATE: I created simple test project as requested (thanks for looking into it).

解压在测试项目中有效,但它正在加载不同的模块.调试/模块窗口指出异常抛出项目使用 System.IO.Compression.dll 4.06.24705.1,工作项目使用 1.00.24301.1.

The unzip works in the test project, but it is loading a different module. The Debug/Modules window states that the exception throwing project uses System.IO.Compression.dll 4.06.24705.1, the working project uses 1.00.24301.1.

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

I uploaded both project.lock.json files for comparison https://1drv.ms/f/s!AqROiejT4oI3lL1q1tu3iJcfA2tKyg.

推荐答案

根据你上传的project.lock.json",我觉得这里的问题可能与System.IO.Compression 4.3.0 包.

According to the "project.lock.json" you've uploaded, I think the problem here may be related to the System.IO.Compression 4.3.0 package.

在抛出异常的项目中,你可以发现它使用了System.IO.Compression 4.3.0",如下所示:

In the exception throwing project, you can find it uses "System.IO.Compression 4.3.0" like following:

"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":

And in the working project, it uses "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 来重现您的问题.压缩 4.3.0 包如下:

It seems that System.IO.Compression 4.3.0 package can't be used in UWP project for now. Currently the latest stable version of "Microsoft.NETCore.UniversalWindowsPlatform" package uses "System.IO.Compression 4.1.1" package. And you should be able to reproduce your issue with the working project by adding System.IO.Compression 4.3.0 package in it like following:

{
  "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".

So to fix this issue, I'd suggest you check the reference of your project and make sure there is no "System.IO.Compression 4.3.0" package. If you do need to use "System.IO.Compression" package, you can try to downgrade it to "4.1.1".

这篇关于解压会抛出“无法正确加载底层压缩例程"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆