imazen / imageflow-dotnet

The official .NET API for Imageflow, the Rust image processing and optimization engine for web servers
GNU Affero General Public License v3.0
143 stars 25 forks source link

Imageflow module not found when deployed to Azure Functions (2.0 Runtime) #17

Closed pompiamp closed 4 years ago

pompiamp commented 4 years ago

Hi, We are having an exception when loading nativeRuntime in azure functions (.net core 2.0).

This is the exception

Looking for "imageflow.dll" Subdir="x86", IsUnix=False, IsDotNetCore=True Before searching: Unable to load DLL 'imageflow' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) File not found: D:\Program Files (x86)\SiteExtensions\Functions\2.0.14248\32bit\x86\imageflow.dll File not found: D:\Program Files (x86)\SiteExtensions\Functions\2.0.14248\32bit\imageflow.dll File not found: D:\home\site\wwwroot\bin\x86\imageflow.dll File not found: D:\home\site\wwwroot\bin\imageflow.dll File not found: D:\Program Files (x86)\SiteExtensions\Functions\2.0.14248\32bit\runtimes\win-x86\native\x86\imageflow.dll File not found: D:\Program Files (x86)\SiteExtensions\Functions\2.0.14248\32bit\runtimes\win-x86\native\imageflow.dll File not found: D:\home\site\wwwroot\bin\runtimes\win-x86\native\x86\imageflow.dll File not found: D:\home\site\wwwroot\bin\runtimes\win-x86\native\imageflow.dll at Imageflow.Bindings.NativeMethods.imageflow_context_create(UInt32 imageflow_abi_ver_major, UInt32 imageflow_abi_ver_minor) at Imageflow.Bindings.JobContextHandle.<>c.<.ctor>b__0_0() at Imageflow.Bindings.NativeLibraryLoader.FixDllNotFoundException[T](String basename, Func1 invokingOperation, IEnumerable1 customSearchDirectories)

Is similar to this Issue

13

These are our references:

<PackageReference Include="Imageflow.Net" Version="0.7.1" />
<PackageReference Include="Imageflow.NativeRuntime.win-x86_64" Version="1.4.10-rc50" />
<PackageReference Include="Imageflow.NativeRuntime.win-x86" Version="1.4.10-rc50" />

If we dig into our deployments paths in azure we can find the runtime (imageflow.dll) at this location:

D:\home\site\wwwroot\runtimes\win-x86\native\imageflow.dll

But it does not exists in the paths that imageflow is trying to get.

We've looked at the FixDllNotFoundException method and thought about this possible fix (adding this path):

yield return Path.Combine( Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory), "runtimes", PlatformRuntimePrefix.Value + "-" + ArchitectureSubdir.Value, "native");

another solution we've thought, is to be able to pass a customSearchDirectoriesparam to the JobContextHandle's constructor

lilith commented 4 years ago

Adding a parent folder to assembly search is something of a security problem. However, if the name if the folder you are dropping is "bin", it seems much safer. How about using an "if" statement to verify the folder is named "bin", then yield return Path.Combine( Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory), "runtimes", PlatformRuntimePrefix.Value + "-" + ArchitectureSubdir.Value, "native")?

I would accept a pull request for this.

pompiamp commented 4 years ago

Adding a parent folder to assembly search is something of a security problem. However, if the name if the folder you are dropping is "bin", it seems much safer. How about using an "if" statement to verify the folder is named "bin", then yield return Path.Combine( Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory), "runtimes", PlatformRuntimePrefix.Value + "-" + ArchitectureSubdir.Value, "native")?

I would accept a pull request for this.

Thanks @lilith I've sent a PR: https://github.com/imazen/imageflow-dotnet/pull/18

lilith commented 4 years ago

I've released your changes with 0.7.2. Thank you so much!