2

I wrote the following simple program to test:

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!");
                }
            }
        }
    }
}

Per this page, I ran dotnet new nuget from the HelloZip project directory, added the recommended package sources in nuget.config, then ran the following commands:

dotnet add package Microsoft.DotNet.ILCompiler -v 1.0.0-alpha-*
dotnet publish -r win-x64 -c release -o out
out\HelloZip.exe

I got the following error:

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

Am I making a mistake, or does the AOT compiler just not properly support System.IO.Compression yet?

Svek
  • 12,350
  • 6
  • 38
  • 69
Shay Guy
  • 1,010
  • 1
  • 10
  • 21

1 Answers1

2

You're hitting a known unimplemented functionality. The workaround is to copy clrcompression.dll next to the compiled executable manually for now. See details here: https://github.com/dotnet/corert/issues/5496

  • I added clrcompression.dll to the directory (version 4.6.26515.6) and the only difference was that the inner DllNotFoundException was replaced with an EntryPointNotFoundException: `Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll'.` – Shay Guy Jun 23 '18 at 00:29
  • Was able to get a newer version of the DLL from elsewhere. Thanks for pointing me in the right direction! – Shay Guy Jun 25 '18 at 04:00