Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find an entry point named 'Environment_SetEnv' in DLL 'Magick.NET-Q8-x64.Native.dll'

Upgraded to latest ImageMagick / Magick.NET (7.0.2.901), and it built and ran fine locally, but explodes on the server with this error.

Unable to find an entry point named 'Environment_SetEnv' in DLL 'Magick.NET-Q8-x64.Native.dll'.

Seems to be a new issue. Judging by the change desc here:

https://magick.codeplex.com/discussions/650746

The VC Runtimes are no longer required, so installing them wouldn't be the issue - and, I've installed 2008, 2012 and 2015 VC runtimes for prior versions of the library, which worked fine.

Windows Server 2008 64-bit, 64-bit .Net 4 in IIS.

Current workaround is to roll back to 7.0.0.22, which runs without error.

Install-Package Magick.NET-Q8-AnyCPU -Version 7.0.0.22

ImageMagick.X64.Environment_SetEnv(IntPtr name, IntPtr value)

like image 481
Chris Moschini Avatar asked Aug 24 '16 15:08

Chris Moschini


2 Answers

I had this issue a couple months back and eventually found two separate causes:

  1. AnyCPU Conflict with Previous Versions

    Problem: Magick.NET caches the native library in a temp directory unless it already exists (Relevant source code). Since I had previously tested with the Q8-x64 version (which doesn't test for CPU architecture), the Magick.NET-Q8-x64.Native.dll already existed and was not overwritten.

    Resolution: Delete the native library's temp directory. On my version of Windows, it was located at %TEMP%\Magick.NET.{TargetFramework}.{MagickNETVersion}. The Q8-AnyCPU version then extracted a new native library with the Environment_SetEnv method.

  2. Lack of Permissions in Cache Directory

    Problem: The native library was cached in a directory with restricted permissions for executing code.

    Resolution: Change the cache directory's location. My solution is the following code.

    #if DEBUG
    private static bool MagickCacheDirectoryIsSet = false;
    
    public DefaultConstructor()
    {
        if (!MagickCacheDirectoryIsSet)
        {
            ImageMagick.MagickAnyCPU.CacheDirectory = @"path\to\more\permissive\directory";
            MagickCacheDirectoryIsSet = true;
        }
    }
    #endif
    
like image 156
Tristan Reischl Avatar answered Nov 03 '22 00:11

Tristan Reischl


Follow these steps:

  1. Go to NuGet package manager for the solution (not the project)

  2. Uninstall any previous versions of Magick.net

  3. Install new version of Magick.net to desired projects

  4. Go to the bin folder of the main project and delete any magick.net file

  5. Run your solution

I successfully tested this method on VS2017 and Magick.net 7.6.1 (previous installation was 7.4.4)

like image 44
Saeed Mousavi Avatar answered Nov 03 '22 02:11

Saeed Mousavi