Solved: Unable to load ‘chilkatDnCore-9_5_0’ or one of its dependencies in Azure functions
Problem:
new Chilkat.Global().UnlockBundle(ChilkatKey);
Unable to load DLL 'chilkatDnCore-9_5_0' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) System.DllNotFoundException : Unable to load DLL 'chilkatDnCore-9_5_0' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Chilkat.Global.CkGlobalU_CreateW()
Solution:
The problem is that the .NET Core runtime in the Azure V2 function environment cannot locate the native DLL.
Some Additional Information:
See https://docs.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke
The native library (DLL) is referenced by DllImport statements such as this:
[DllImport("chilkatDnCore-9_5_0", EntryPoint = "CkGlobalU_CreateW", CharSet = CharSet.Unicode)]
private static extern System.IntPtr CkGlobalU_CreateW();
The name of the DLL is highlighted in red above. This DLL (chilkatDnCore-9_5_0.dll) is contained in the ChilkatNativeLib NuGet package.
It’s the native Win32 DLL loading rules that govern things. The P/Invoke marshaller just calls LoadLibrary.
The directories searched for the DLL are described in detail here:
https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime/8861895
and also here:
https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order?redirectedfrom=MSDN