7

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)

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
  • Would you mind starting a topic here: https://magick.codeplex.com/discussions? I could ask you some questions then. – dlemstra Aug 25 '16 at 07:50
  • You managed to solve this already? I have the same problem on my server. While it works fine locally – Ron Sijm Oct 06 '16 at 08:10
  • I wanted to gather more diagnostics before posting a bug, and never did it. The fact it has to explode on the server makes gathering those diagnostics a bigger task, since I really need to put it out on a site designed to fail. Will swing back around to it though. But as mentioned workaround is easy, rollback to 7.0.0.22 – Chris Moschini Oct 06 '16 at 17:04

3 Answers3

8

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
    
Tristan Reischl
  • 251
  • 4
  • 8
  • 1
    I performed #1 (in C:\Windows\Temp), and I did this: https://stackoverflow.com/a/23308437/1325179. Then I restarted the application pool. – user1325179 Oct 10 '17 at 21:19
  • All I had to do was recycle the application pool. I didn't need to delete any temp files. – joeshmoe301 May 17 '18 at 15:28
1

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)

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Saeed Mousavi
  • 289
  • 1
  • 2
  • 13
0

Had the same issue, deleting the all magick dlls from the bin folder and reinstall solved it.

eladm
  • 176
  • 1
  • 5