.net core 为什么CoreRT编译的程序无法处理ZIP文件?
我编写了以下简单程序进行测试:.net core 为什么CoreRT编译的程序无法处理ZIP文件?,.net-core,system.io.compression,corert,.net Core,System.io.compression,Corert,我编写了以下简单程序进行测试: using System; using System.IO; using System.IO.Compression; namespace HelloZip { class Program { static void Main(string[] args) { string path = Path.Combine(AppContext.BaseDirectory, "test.zip");
using System;
using System.IO;
using System.IO.Compression;
namespace HelloZip
{
class Program
{
static void Main(string[] args)
{
string path = Path.Combine(AppContext.BaseDirectory, "test.zip");
using (ZipArchive z = ZipFile.Open(path, ZipArchiveMode.Create))
{
var f = z.CreateEntry("hello.txt");
using (StreamWriter writer = new StreamWriter(f.Open()))
{
writer.Write("Hello World!");
}
}
}
}
}
根据,我从HelloZip项目目录运行了dotnet new nuget
,在nuget.config中添加了推荐的包源,然后运行了以下命令:
dotnet add package Microsoft.DotNet.ILCompiler -v 1.0.0-alpha-*
dotnet publish -r win-x64 -c release -o out
out\HelloZip.exe
我得到了以下错误:
Unhandled Exception: System.IO.Compression.ZLibException: The underlying compression routine could not be loaded correctly. ---> System.DllNotFoundException: Unable to load DLL 'clrcompression.dll': The specified module could not be found.
at HelloZip!<BaseAddress>+0x1199e7
at HelloZip!<BaseAddress>+0x119904
at Interop.zlib.DeflateInit2_(ZLibNative.ZStream&, ZLibNative.CompressionLevel, ZLibNative.CompressionMethod, Int32, Int32, ZLibNative.CompressionStrategy) + 0x48
at System.IO.Compression.ZLibNative.ZLibStreamHandle.DeflateInit2_(ZLibNative.CompressionLevel, Int32, Int32, ZLibNative.CompressionStrategy) + 0x4f
at System.IO.Compression.Deflater.DeflateInit(ZLibNative.CompressionLevel, Int32, Int32, ZLibNative.CompressionStrategy) + 0x59
--- End of inner exception stack trace ---
at System.IO.Compression.Deflater.DeflateInit(ZLibNative.CompressionLevel, Int32, Int32, ZLibNative.CompressionStrategy) + 0x1db
at System.IO.Compression.Deflater..ctor(CompressionLevel, Int32) + 0x50
at System.IO.Compression.DeflateStream.InitializeDeflater(Stream, Boolean, Int32, CompressionLevel) + 0x39
at System.IO.Compression.ZipArchiveEntry.GetDataCompressor(Stream, Boolean, EventHandler) + 0x4b
at System.IO.Compression.ZipArchiveEntry.OpenInWriteMode() + 0x65
at HelloZip.Program.Main(String[]) + 0x75
at HelloZip!<BaseAddress>+0x1716a2
未处理的异常:System.IO.Compression.ZLibException:无法正确加载基础压缩例程。-->System.DllNotFoundException:无法加载DLL“clrcompression.DLL”:找不到指定的模块。
你好+0x1199e7
你好+0x119904
在Interop.zlib.DeflateInit2_2;(ZLibNative.ZStream&,ZLibNative.CompressionLevel,ZLibNative.CompressionMethod,Int32,Int32,ZLibNative.CompressionStrategy)+0x48
在System.IO.Compression.ZLibNative.ZLibStreamHandle.DeflateInit2(ZLibNative.CompressionLevel,Int32,Int32,ZLibNative.CompressionStrategy)+0x4f
在System.IO.Compression.Deflater.DeflateInit(ZLibNative.CompressionLevel,Int32,Int32,ZLibNative.CompressionStrategy)+0x59
---内部异常堆栈跟踪的结束---
在System.IO.Compression.Deflater.DeflateInit(ZLibNative.CompressionLevel,Int32,Int32,ZLibNative.CompressionStrategy)+0x1db
在System.IO.Compression.Deflater..ctor(压缩级别,Int32)+0x50时
在System.IO.Compression.Deflam.InitializedFlater(流、布尔、Int32、压缩级别)+0x39
在System.IO.Compression.ZipArchiveEntry.GetDataCompressor(流、布尔、EventHandler)+0x4b
在System.IO.Compression.ZipArchiveEntry.OpenInWriteMode()中+0x65
在HelloZip.Program.Main(字符串[])处+0x75
你好+0x1716a2
是我犯了错误,还是AOT编译器还没有正确支持System.IO.Compression?您遇到了一个已知的未实现的功能。解决方法是暂时手动将clrcompression.dll复制到已编译的可执行文件旁边。请参阅此处的详细信息:我已将clrcompression.dll添加到目录中(版本4.6.26515.6)唯一的区别是内部DllNotFoundException被EntryPointNotFoundException替换:
无法在DLL“clrcompression.DLL”中找到名为“CompressionNative”的入口点。
能够从其他地方获得DLL的更新版本。谢谢你给我指明了正确的方向!