hey-red / Mime

.NET wrapper for libmagic
MIT License
83 stars 21 forks source link

"Could not find any valid magic files!" when included in a Nuget package #44

Closed d00ML0rDz closed 2 years ago

d00ML0rDz commented 2 years ago

I've included the Mime package as part of my own Nuget package NsfwSpy, but when I run the following lines of code I get the error message "Could not find any valid magic files!" on my fresh Ubuntu VM.

var nsfwSpy = new NsfwSpy();
var result = nsfwSpy.ClassifyImage(@"C:\Users\username\Documents\flower.jpg");

Is there something I need to do to include the libmagic dependency in my Nuget package?

hey-red commented 2 years ago

Database with file signatures magic.mgc should be placed along with libmagic-1.so(/bin/ or runtimes/linux-x64/native/ directories). It depends on how you publish the application. Also, it can be set via setter MimeGuesser.MagicFilePath: MimeGuesser.MagicFilePath = "/path/to/magic/file/magic.mgc";

But it seems like you are use 3.3.0 version. So, try to install latest package, it should works out of box.

d00ML0rDz commented 2 years ago

The base NsfwSpy project is just a class library so when I either publish or pack it, the magic.mgc and libmagic-1.so files aren't being included in the .nupkg file or the release folders. However when adding the NsfwSpy package to a project (e.g. an empty console application), the Mime package also gets installed due to being a dependency.

In that test console app, I can see the magic.gc and libmagic-1.so files in the ConsoleApp/bin/Debug/net6.0/runtimes/linux-x64/native/ folder. So not quite sure why Mime isn't picking them up.

image

hey-red commented 2 years ago

This is because before 3.4.0 library check database only inside directory where is Mime.dll placed. In latest version it search magic.mgc inside runtime/{RID}/native too. This should be cover situations when application published without specify target runtime.

d00ML0rDz commented 2 years ago

Cool, I'll have a go with 3.4.0 and see how it goes. Thanks for the help so far.

d00ML0rDz commented 2 years ago

Yep, version 3.4.0 fixed it. Sorry for not trying this to start with.

Thanks for the help!