Question Can't work with DupImageLib

sebescudie

New member
Joined
Sep 11, 2018
Messages
2
Programming Experience
3-5
Hey all,

Trying to create a small test console app with DupImageLib, a perceptual hashing library. For starters, I've created a simple console app that should display the average hash of an image, here's the code :

C#:
[...]
using DupImageLib;


namespace ImageHashing
{
    class Program
    {
        static void Main(string[] args)
        {
            var imageHasher = new ImageHashes(new ImageMagickTransformer());
            var hash = imageHasher.CalculateAverageHash64(@"path_to_my_image.png");
            Console.WriteLine(hash);
            Console.ReadKey();
        }
    }
}

As you can see, it's pretty much the example provided in the repo's README. Unfortunately, the app won't start because VS raises the following exception :

C#:
System.DllNotFoundException : 'Impossible de charger la DLL 'Magick.NET-Q8-x64.Native.dll': Le module spécifié est introuvable. (Exception de HRESULT : 0x8007007E)'

And indeed, the specified dll is not present in the bin/Debug folder, neither in the dependency list in the Solution Explorer. Weird thing is it is marked as installed in the Nuget manager.

I downloaded this dll seperaterly and manually pasted it : then it works. Here are my questions :

1. Why is the dll marked as added in Nuget Manager but does not show up on the Solution Explorer ?
2. What am I supposed to do if I wanna distribute my app ? Manually adding the dll seems like a dirty workaround.

I'm using VS2017 15.3.2 on W10.

Thanks in advance for your help !

seb
 
I just created a C# Console Application project and added that NuGet package. One of the references it adds is Magick.NET.Core-Q8 and I can see Magick.NET.Core-Q8.dll in my output folder. Are you seeing the same thing?

Based on the name of the DLL that cannot be found, it's not a .NET assembly but rather something written in C/C++ that exports functions that the .NET assembly calls via Platform Invoke. So your app makes calls to managed code in DupImageLib.dll, which makes calls to managed code in Magick.NET.Core-Q8.dll, which makes calls to unmanaged code in Magick.NET-Q8-x64.Native.dll. In that case, it's not possible to reference that DLL in your project because a .NET project can only reference .NET assemblies and COM components.

Probably your best bet is to add that DLL to your project directly, set its Build Action property to Content and set Copy Local to True. That way, the build process will treat it just like it would normally treat text files and the like, which is to say that no processing will be done on it and it will simply be copied as is to the output folder.
 
I just created a C# Console Application project and added that NuGet package. One of the references it adds is Magick.NET.Core-Q8 and I can see Magick.NET.Core-Q8.dll in my output folder. Are you seeing the same thing?

Yep ! The native dll on the other hand was not present.

Based on the name of the DLL that cannot be found, it's not a .NET assembly but rather something written in C/C++ that exports functions that the .NET assembly calls via Platform Invoke. So your app makes calls to managed code in DupImageLib.dll, which makes calls to managed code in Magick.NET.Core-Q8.dll, which makes calls to unmanaged code in Magick.NET-Q8-x64.Native.dll. In that case, it's not possible to reference that DLL in your project because a .NET project can only reference .NET assemblies and COM components.

Probably your best bet is to add that DLL to your project directly, set its Build Action property to Content and set Copy Local to True. That way, the build process will treat it just like it would normally treat text files and the like, which is to say that no processing will be done on it and it will simply be copied as is to the output folder.

Thanks so much for that clear explanation, did not know VS would not pick those ! I'll add them manually then.

Cheers !

seb
 
Back
Top Bottom