8000 Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll' · Issue #634 · dotnet-script/dotnet-script · GitHub
[go: up one dir, main page]

Skip to content

Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll' #634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SvenEssentry opened this issue Aug 26, 2021 · 10 comments

Comments

@SvenEssentry
Copy link

Since version 1.2.0 an issue occurs when using System.IO.Compression.ZipArchive (an possibly other native implementations).
After uninstalling version 1.2.0 and installing 1.1.0, the issue was resolved.

This is the piece of code, that throws an exception

using(var zipFile = new System.IO.Compression.ZipArchive(zipStream, System.IO.Compression.ZipArchiveMode.Create)){
    // Get artifacts from project
    var artifactDirectory = Path.Combine(project.FullName, "bin", configuration);
    if (Directory.GetDirectories(artifactDirectory).Any(e => e.EndsWith("net5.0"))){
        artifactDirectory = Path.Combine(artifactDirectory, "net5.0");
    }
    // Copy all artifacts to the bin/ directory
    foreach(var artifactFile in Directory.GetFiles(artifactDirectory, "*.*", SearchOption.AllDirectories)){
        var entrySubstring = Path.Combine("bin", artifactFile.Substring(artifactDirectory.Length + 1));

        // Following line (41) throws Exception -------------------------------------------------------------------------------
        using(var writeStream = zipFile.CreateEntry(entrySubstring).Open()){
            using (var readStream = File.OpenRead(artifactFile)){
                readStream.CopyTo(writeStream);
                Console.WriteLine("Creating '" + entrySubstring + "' from '" + artifactFile);
            }
        }
    }
// ...
}
System.AggregateException: One or more errors occurred. (The underlying compression routine could not be loaded correctly.) (The underlying compression routine could not be loaded correctly.) (The underlying compression routine could not be loaded correctly.) (The underlying compression routine could not be loaded correctly.)
 ---> System.IO.Compression.ZLibException: The underlying compression routine could not be loaded correctly.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll'.
   at Interop.zlib.DeflateInit2_(ZStream& stream, CompressionLevel level, CompressionMethod method, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.ZLibStreamHandle.DeflateInit2_(CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.CreateZLibStreamForDeflate(ZLibStreamHandle& zLibStreamHandle, CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)      
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   --- End of inner exception stack trace ---
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   at System.IO.Compression.DeflateStream.InitializeDeflater(Stream stream, Boolean leaveOpen, Int32 windowBits, CompressionLevel compressionLevel)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen, Int32 windowBits)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen)
   at System.IO.Compression.ZipArchiveEntry.GetDataCompressor(Stream backingStream, Boolean leaveBackingStreamOpen, EventHandler onClose)
   at System.IO.Compression.ZipArchiveEntry.OpenInWriteMode()
   at System.IO.Compression.ZipArchiveEntry.Open()
   at Submission#0.<<Initialize>>b__0_1(DirectoryInfo project) in C:\projects\export\build_scripts\bundle.csx:line 41
   at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IList`1 list, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
   at Submission#0.<<Initialize>>d__0.MoveNext() in C:\projects\export\build_scripts\bundle.csx:line 18
--- End of stack trace from previous location ---
   at Dotnet.Script.Core.ScriptRunner.Execute[TReturn](String dllPath, IEnumerable`1 commandLineArgs) in C:\Users\VssAdministrator\AppData\Local\Temp\tmp5CA8\Dotnet.Script.Core\ScriptRunner.cs:line 112
 ---> (Inner Exception #1) System.IO.Compression.ZLibException: The underlying compression routine could not be loaded correctly.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll'.
   at Interop.zlib.DeflateInit2_(ZStream& stream, CompressionLevel level, CompressionMethod method, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.ZLibStreamHandle.DeflateInit2_(CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.CreateZLibStreamForDeflate(ZLibStreamHandle& zLibStreamHandle, CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)      
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   --- End of inner exception stack trace ---
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   at System.IO.Compression.DeflateStream.InitializeDef
8000
later(Stream stream, Boolean leaveOpen, Int32 windowBits, CompressionLevel compressionLevel)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen, Int32 windowBits)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen)
   at System.IO.Compression.ZipArchiveEntry.GetDataCompressor(Stream backingStream, Boolean leaveBackingStreamOpen, EventHandler onClose)
   at System.IO.Compression.ZipArchiveEntry.OpenInWriteMode()
   at System.IO.Compression.ZipArchiveEntry.Open()
   at Submission#0.<<Initialize>>b__0_1(DirectoryInfo project) in C:\projects\export\build_scripts\bundle.csx:line 41
   at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()<---

 ---> (Inner Exception #2) System.IO.Compression.ZLibException: The underlying compression routine could not be loaded correctly.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll'.
   at Interop.zlib.DeflateInit2_(ZStream& stream, CompressionLevel level, CompressionMethod method, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.ZLibStreamHandle.DeflateInit2_(CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.CreateZLibStreamForDeflate(ZLibStreamHandle& zLibStreamHandle, CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)      
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   --- End of inner exception stack trace ---
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   at System.IO.Compression.DeflateStream.InitializeDeflater(Stream stream, Boolean leaveOpen, Int32 windowBits, CompressionLevel compressionLevel)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen, Int32 windowBits)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen)
   at System.IO.Compression.ZipArchiveEntry.GetDataCompressor(Stream backingStream, Boolean leaveBackingStreamOpen, EventHandler onClose)
   at System.IO.Compression.ZipArchiveEntry.OpenInWriteMode()
   at System.IO.Compression.ZipArchiveEntry.Open()
   at Submission#0.<<Initialize>>b__0_1(DirectoryInfo project) in C:\projects\export\build_scripts\bundle.csx:line 41
   at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()<---

 ---> (Inner Exception #3) System.IO.Compression.ZLibException: The underlying compression routine could not be loaded correctly.
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'CompressionNative_DeflateInit2_' in DLL 'clrcompression.dll'.
   at Interop.zlib.DeflateInit2_(ZStream& stream, CompressionLevel level, CompressionMethod method, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.ZLibStreamHandle.DeflateInit2_(CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)
   at System.IO.Compression.ZLibNative.CreateZLibStreamForDeflate(ZLibStreamHandle& zLibStreamHandle, CompressionLevel level, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy)      
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   --- End of inner exception stack trace ---
   at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits)
   at System.IO.Compression.DeflateStream.InitializeDeflater(Stream stream, Boolean leaveOpen, Int32 windowBits, CompressionLevel compressionLevel)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen, Int32 windowBits)
   at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionLevel compressionLevel, Boolean leaveOpen)
   at System.IO.Compression.ZipArchiveEntry.GetDataCompressor(Stream backingStream, Boolean leaveBackingStreamOpen, EventHandler onClose)
   at System.IO.Compression.ZipArchiveEntry.OpenInWriteMode()
   at System.IO.Compression.ZipArchiveEntry.Open()
   at Submission#0.<<Initialize>>b__0_1(DirectoryInfo project) in C:\projects\export\build_scripts\bundle.csx:line 41
   at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica`1.ExecuteAction(Boolean& yieldedBeforeCompletion)
   at System.Threading.Tasks.TaskReplicator.Replica.Execute()<---
@seesharper
Copy link
Collaborator

@hrumhurum Another issue related to assembly loading. Have not looked into the details, but seems related to native dlls

@SvenEssentry
Copy link
Author

Maybe related? dotnet/corert#5496

@hrumhurum
Copy link
Contributor

A naïve approach trying to reproduce the issue works as expected.

test.csx:

using System.IO.Compression;

var ms = new MemoryStream();
var cs = new DeflateStream(ms, CompressionMode.Compress);

var bw = new BinaryWriter(cs);
string s = "Test Test Test Test Test Test Test Test Test Test Test Test Test";
bw.Write(s);
bw.Flush();

bool result = ms.Length > 0 && ms.Length < s.Length;

Console.WriteLine(result ? "OK" : "NOK");

The output of dotnet-script test.csx:

OK

Running dotnet-script --version renders:

1.2.0

@SvenEssentry, can you please send a reproduction sample?

@seesharper
Copy link
Collaborator

@hrumhurum

One thing I have noticed.

If a script does this

var context = AssemblyLoadContext.CurrentContextualReflectionContext;

It will return null. Should this be the ScriptAssemblyLoadContext

@hrumhurum
Copy link
Contributor

It will return null. Should this be the ScriptAssemblyLoadContext

It should not return null. Are you trying this in interactive mode?

@seesharper
Copy link
Collaborator
using System.Runtime.Loader;
var loadContext = AssemblyLoadContext.CurrentContextualReflectionContext;
Console.WriteLine(loadContext.GetType());

@hrumhurum
Copy link
Contributor
hrumhurum commented Aug 26, 2021

var loadContext = AssemblyLoadContext.CurrentContextualReflectionContext;

Was able to reproduce it with dotnet-script 1.2.0 global tool installed, but not with locally built binaries.

Upon closer inspection, it turned out that %USERPROFILE%\.dotnet\tools\.store\dotnet-script\1.2.0\dotnet-script\1.2.0\tools\net5.0\any\Dotnet.Script.Core.dll file misses that instruction:

#if NETCOREAPP3_0_OR_GREATER
using var contextualReflectionScope = assemblyLoadContext != null ? assemblyLoadContext.EnterContextualReflection() : default;
#endif

Have no idea how that could happen, other than a bug in toolchain version installed at the build server.

I will cover this with a unit test and will send a PR.

@seesharper
Copy link
Collaborator

Maybe just?

!NETSTANDARD2_0

@hrumhurum
Copy link
Contributor

!NETSTANDARD2_0

That line does not need NETCOREAPP3_0_OR_GREATER condition anymore as we dropped netcoreapp2.1.

Not a problem, as it will be covered in a test after implementation of opt-in option. It seems that the build server just has an older or buggy version that does not understand NETCOREAPP3_0_OR_GREATER.

@seesharper
Copy link
Collaborator

Perfect. Let's hope that solves the issues 👍😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0