Reputation: 769
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())
{
throws at entry.Open() the following error. "The underlying compression routine could not be loaded correctly."
with the inner exception
"Unable to load DLL 'clrcompression.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
Important to note:
using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create,true))
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).
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.
I uploaded both project.lock.json files for comparison https://1drv.ms/f/s!AqROiejT4oI3lL1q1tu3iJcfA2tKyg.
Upvotes: 1
Views: 3311
Reputation: 15413
Fix for me was to add this to the first PropertyGroup
in the .csproj file:
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
Visual Studio normally implicitly pulls in 1.6.1 for .NET Standard projects, which has the problematic System.IO.Compression 4.3.0. The directive tells it to pull down 1.6.0 instead, which depends on System.IO.Compression 4.1.1 (which works on Windows Phone).
Just make sure you don't have another NuGet reference which is pulling in 4.3.0. The correct file version for System.IO.Compression.dll is 1.0.24301.1 and the broken one is 4.6.xxxx .
Upvotes: 3
Reputation: 769
I found the root cause. As Jay Zuo said, the problem is that in the project.lock.json is somehow referencing the "System.IO.Compression 4.3.0".
I am not directly referencing it in any project.json file. I am indirectly referencing it by a .NETSTANDARD1.1 project with a reference to the "NETStandard.Library": "1.6.1".
By using nuget.org I searched for a "NETStandard.Library" version using the older System.IO.Compression 4.1.1, which is "NETStandard.Library" 1.6.0.
Using the "NETStandard.Library" 1.6.0. in the .NETSTANDARD 1.1 project fixed the unzip error.
I uploaded a sample solution to reproduce the error. https://1drv.ms/f/s!AqROiejT4oI3lMMc_jWogCQy36awrA
Upvotes: 3
Reputation: 15758
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.
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"
},
...
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"
},
...
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": { }
}
}
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".
Upvotes: 2