System.DllNotFoundException
Charltsing opened this issue · comments
Magick.NET version
14.5.0
Environment (Operating system, version and so on)
Windows 11 Pro Insider Preview(11.0.26040), x64
Description
I use Magick.net 14.5.0 to develop my software , One of my user report it Causing my soft crashes when it start up On his PC ,
it is my code when crash: ImageMagick.ResourceLimits.LimitMemory(new ImageMagick.Percentage(80))
Windows Event Viewer report: System.DllNotFoundException
Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.42.34438 installed.
My user copy the old Magick.Native-Q16-x64.DLL ( 7.1.1.35) to my soft directory instead of 7.1.1.44 , it work fine.
Is the latest version of Magick.Native-Q16-x64.DLL missing any dependencies in Windows 11 ?
Or maybe I did something wrong ?
I tested the software on Windows 10 22h2 Pro and it worked fine.
Here are the details of the error message in Windows Event Viewer:
日志名称: Application
来源: .NET Runtime
日期: 2025/3/17 19:44:55
事件 ID: 1026
描述:
应用程序: xxxx.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.DllNotFoundException
在 ImageMagick.Environment+NativeMethods+X64.Environment_Initialize()
在 ImageMagick.Environment.Initialize()
在 ImageMagick.ResourceLimits+NativeResourceLimits..cctor()
异常信息: System.TypeInitializationException
在 ImageMagick.ResourceLimits+NativeResourceLimits.LimitMemory(Double)
在 ImageMagick.ResourceLimits.LimitMemory(ImageMagick.Percentage)
在 MD.K()
在 tE.K()
It looks like the native library is not on their system? Is it possible there is an issue in your distribution? In the past I have also use Dependency Walker to validate issues with the library. It feels a bit odd that it works in Windows 10 but not on Windows 11. I would advise you to create a VM that is similar to their environment to check if you can reproduce the issue of that user.
I don't have the conditions to create the corresponding virtual machine
I have only received one report. This crash might be related to the version of Windows 11 ?
Others have reported that it work fine on their Windows 11.
Perhaps the Magick.Native-Q16-x64.DLL 7.1.1.44 is missing something.
can you tell me what its dependence is ? the version of vc or ...
The DLLNotFoundException
doesn't look like a missing dependency. Did you check that everything was correctly deployed to that machine?
I don't have access to user computers. If it's a deployment issue, why is version 7.1.1.35 work fine ?
my user test ImageGlass Magick.Native-Q16-HDRI-OpenMP-x64.dll 7.1.1.41(ImageGlass_9.2.0.1208_x64) , it work fine.
but i rebuild ImageGlass with Magick.Native-Q16-x64.dll 7.1.1.44, it can not start up.
I am considering testing more native library versions
I really suspect that using a different dll changes something in your packaging and that breaks it.
my user test result:
Magick.Net , Magick.Native-Q16-x64, status
14.5.0 , 7.1.1.44 , crash
14.3.0 , 7.1.1.43 , crash
14.2.0 , 7.1.1.41 , ok
14.1.0 , 7.1.1.40 , ok
14.0.0 , 7.1.1.38 , ok
13.10.0 , 7.1.1.35 , ok
only copy Magick.Native-Q16-x64.dll to installed directory
test code:
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoOptimization | System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
[System.Security.SecurityCritical]
private void SetMagickLimitMemory()
{
try
{
ImageMagick.ResourceLimits.LimitMemory(new ImageMagick.Percentage(80));
}
catch (Exception e)
{
Log.Error($"{e.Message}");
Log.Error($"StackTrace:{e.StackTrace}");
}
}
log error is:
“NativeResourceLimits” , The type initializer to throw an exception
StackTrace:
ImageMagick.ResourceLimits.NativeResourceLimits.LimitMemory(Double percentage)
ImageMagick.ResourceLimits.LimitMemory(Percentage percentage)
************** 异常文本 **************
System.DllNotFoundException: 无法加载 DLL“Magick.Native-Q16-x64.dll”: 动态链接库(DLL)初始化例程失败。 (异常来自 HRESULT:0x8007045A)。
在 ImageMagick.Environment.NativeMethods.X64.Environment_Initialize()
在 ImageMagick.Environment.Initialize()
在 ImageMagick.ResourceLimits.NativeResourceLimits..cctor()
Maybe Windows11 Profession Insider Preview(11.0.26040) is missing some DLL
or 7.1.1.43/44 is missing some DLL.
Windows 11 24H2 work fine.
I have no idea what is causing this issue. Maybe it's related that they are using an Insider build of Windows.
Did you figure out what caused this?
I don't know, but I advised the user to change the operating system version
This issue cannot be analyzed without specific Windows, so it is temporarily put on hold