【问题标题】:ImageMagick : Unable to load DLL 'Magick.Native-Q8-x86.dll'ImageMagick:无法加载 DLL 'Magick.Native-Q8-x86.dll'
【发布时间】:2020-11-26 04:26:31
【问题描述】:

发生了一件非常奇怪的事情。 我想在我的源代码中使用 Image Magick 而不是使用命令行批处理,所以我尝试了 Image Magick.Net (https://recordnotfound.com/Magick-NET-dlemstra-154214) 但是 ....

让我们更准确地描述事物。

  1. 我使用的是 XP Pro SP3 32 位版本 2002 我以管理员身份登录。

我的系统有

  • Microsoft Visual C++ 2012 可再发行版 (x86) 11.0.610.30
  • Microsoft Visual C++ 2017 可再发行版 (x86) 14.11.25325
  1. 我打开 VS 2008

  2. 我在 C# 中创建了一个控制台应用程序类型的新项目。 我将其命名为“TestDLL”。

  3. 在 Program.cs 文件中, 在 'static void Main(string[] args)' 方法中, 我实例化了一个 ImageMagick 对象。

  4. 我从 nuget 站点 https://www.nuget.org/profiles/dlemstra 下载 DLL:

  • Magick.Native-Q8-x86.dll 13,7 MB(14 450 896 字节) 7.0.10.25 版权所有 2013-2020 Dirk Lemstra

  • Magick.NET.Core.dll 1,34 MB(1 407 696 字节) 4.1.0.0 版权所有 2013-2020 Dirk Lemstra

  • Magick.NET-Q8-x86.dll 467 KB(478 928 字节) 7.21.1.0 版权所有 2013-2020 Dirk Lemstra

  1. 我将这些 DLL 复制到这些目录中(假设我使用调试配置文件构建)

'TestDLL' 'TestDLL\bin' 'TestDLL\bin\Debug'

  1. 我在控制台应用程序中引用了 Magick.NET.Core.dll 和 Magick.NET-Q8-x86.dll

  2. 我在 Program.cs 中有一个 using 关键字来检测 MagickImage 对象。

  3. 我在调试配置文件中构建:一切正常(构建成功)

  4. 我启动。

  5. 我得到一个异常:“'NativeMagickSettings' 的类型初始化程序引发了异常。”

这些异常包含一个内部异常:

“无法加载 DLL 'Magick.Native-Q8-x86.dll':找不到指定的过程。(来自 HRESULT 的异常:0x8007007F)”

我不明白它为什么会崩溃...... 我做了所有预期的事情,这是一个非常“简约”的项目,只是为了测试......

我想念什么?

感谢大家的帮助:)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImageMagick;

namespace TestDLL
{
    class Program
    {
        static void Main(string[] args)
        {
            MagickImage image = new MagickImage();
        }
    }
}

堆栈跟踪:

在 ImageMagick.MagickSettings.NativeMagickSettings..ctor() 在 ImageMagick.MagickSettings..ctor() 在 ImageMagick.MagickImage..ctor() 在 TestDLL.Program.Main(String[] args) 在 D:\CODE\StandAlone\TESTS\TestDLL\TestDLL\Program.cs:13 行
在 System.AppDomain._nExecuteAssembly(程序集程序集,字符串 [] args) 在 System.AppDomain.ExecuteAssembly(String assemblyFile, 证据 assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext、ContextCallback 回调、对象状态)在 System.Threading.ThreadHelper.ThreadStart()

我的 VS 安装:

Microsoft Visual Studio 2008 版本 9.0.30729.1 SP Microsoft .NET Framework Version 3.5 SP1 安装版:专业版微软 Visual C# 2008 91605-270-1746647-60768

【问题讨论】:

    标签: c# dll imagemagick windows-xp 32-bit


    【解决方案1】:

    首先我怀疑 DLL 的文件名格式不正确。

    我浏览了源代码,发现:

    public partial class MagickSettings
    {
                #if PLATFORM_x86 || PLATFORM_AnyCPU
                public static class X86
                {
                    #if PLATFORM_AnyCPU
                    static X86() { NativeLibraryLoader.Load(); }
                    #endif
                    [DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
                    public static extern IntPtr MagickSettings_Create();
    } 
    

    DLL的名字是在调用Interop之前动态生成的……

    流程在这里:

    namespace ImageMagick
    {
        internal static class NativeLibrary
        {
            public const string Name = "Magick.Native";
    
            public const string QuantumName = Quantum + OpenMP;
    
            public const string X86Name = Name + "-" + QuantumName + "-x86.dll";
    
            public const string X64Name = Name + "-" + QuantumName + "-x64.dll";
    
    #if Q8
            private const string Quantum = "Q8";
    #elif Q16
            private const string Quantum = "Q16";
    #elif Q16HDRI
            private const string Quantum = "Q16-HDRI";
    #else
    #error Not implemented!
    #endif
    
    #if OPENMP
            private const string OpenMP = "-OpenMP";
    #else
            private const string OpenMP = "";
    #endif
    
    #if PLATFORM_AnyCPU
            public static string PlatformName => Is64Bit ? "x64" : "x86";
    
            public static bool Is64Bit
            {
                get
                {
                    return IntPtr.Size == 8;
                }
            }
    #endif
        }
    }
    

    所以我验证了 NativeLibrary.X86Name = "Magick.Native-Q8-x86.dll"

    所以我怀疑 Interop 调用或 DLL 本身在某种程度上是坏的。

    我编写了一个测试代码,只是为了调用 DLL 进程的开始和结束。

    [DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
    public static extern IntPtr MagickSettings_Create();
    
    [DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
    public static extern void MagickSettings_Dispose(IntPtr instance);
    

    DLL 导出查看器 1.66:

    Magick.Native-Q8-x86.dll : 1186 个导出函数

    函数名称:MagickSettings_Dispose 地址
    :0x10024e90 相对地址 :0x00024e90 序数 :548 (0x224) 文件名:Magick.Native-Q8-x86.dll 类型
    :导出函数

    函数名称:MagickSettings_创建地址
    :0x10024e10 相对地址 :0x00024e10 序数 :541 (0x21d) 文件名:Magick.Native-Q8-x86.dll 类型
    :导出函数

    用这个简单的代码:

    using System;
    using System.Runtime.InteropServices;
    
    public sealed class InteropTest
    {   
        [DllImport("Magick.Native-Q8-x86.dll", EntryPoint = "#541", CallingConvention = CallingConvention.Cdecl )]
        public static extern IntPtr MagickSettings_Create();
    
        [DllImport("Magick.Native-Q8-x86.dll", EntryPoint = "#548", CallingConvention = CallingConvention.Cdecl)]
        public static extern void MagickSettings_Dispose(IntPtr instance);
        
        public InteropTest()
        {
            IntPtr p = MagickSettings_Create();
    
            MagickSettings_Dispose(p);
        }
    }
    

    我得到: 无法加载 DLL 'Magick.Native-Q8-x86.dll':找不到指定的过程。 (来自 HRESULT 的异常:0x8007007F)。

    所以DLL有问题。

    经过调查,我意识到 Magick.Native-Q8-x86.dll 有一个巨大的依赖关系,根据你拥有的操作系​​统(win7、8、10)、你拥有的拱门(32/64)和如果您作为桌面或远程服务器工作。

    运行所有可能在特定配置中丢失的 DLL 需要花费时间,并且每个新配置问题都会以不同的方式再次出现。

    制作一个大的静态 DLL 并不能解决问题,因为它肯定会生成一个千兆字节数据的怪物文件......

    这不是部署场景的好方法。

    我更喜欢切换到便携式应用程序版本。下载简单,安装简单(只需双击),没有依赖噩梦。它甚至适用于 XP。

    唯一的缺点是它没有像 Magick.Net 那样集成在代码中。

    就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-26
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      相关资源
      最近更新 更多