Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load magic1.dll manually in windows #10

Closed
patachi opened this issue Apr 7, 2017 · 25 comments
Closed

Unable to load magic1.dll manually in windows #10

patachi opened this issue Apr 7, 2017 · 25 comments

Comments

@patachi
Copy link

patachi commented Apr 7, 2017

it would be great if you update this :>
ty in advance .

Errors :

  1. Unable to load DLL 'libmagic1': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

  2. An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

Stack Trace :
at HeyRed.Mime.MagicNative.magic_open(MagicOpenFlags flags)
at HeyRed.Mime.Magic..ctor(MagicOpenFlags flags, String dbPath)
at HeyRed.Mime.MimeGuesser.GuessMimeType(Byte[] buffer, Int32 size)
.....

@patachi patachi changed the title Unable to load DLL magic1.dll manually in windows Unable to load magic1.dll manually in windows Apr 7, 2017
@hey-red
Copy link
Owner

hey-red commented Apr 7, 2017

This means that you are trying to use x86 dll in x64 proj or vice versa.
If you need x64 dll, then you can get it here Later, I build an assembly for Windows.

@patachi
Copy link
Author

patachi commented Apr 7, 2017

hmm
I tried both x86 & x64 mode still Unable to load DLL
and the same error :
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B))

@hey-red
Copy link
Owner

hey-red commented Apr 8, 2017

@patachi I'm updated the package with windows support (included x64 dll). Now you do not need to install the DLL manually.

@patachi
Copy link
Author

patachi commented Apr 9, 2017

ohh thank you ^_^

welp i create new classic win form project and added Mime with NuGet (Update Saturday, April 8, 2017 (4/8/2017)) and write a simple code like

    public string TryToGetFileExtension(byte[] fileBuff)
    {
        var fileExtension = "";
        try
        {
            //HeyRed.Mime.MimeGuesser.MagicFilePath = @"magic.mgc";

            var tmpLength = (fileBuff.Length > 512 ? 512 : fileBuff.Length);
            var tmpBuff = new byte[tmpLength];
            Array.Copy(fileBuff, tmpBuff, tmpLength);
            fileExtension = HeyRed.Mime.MimeGuesser.GuessExtension(tmpBuff, tmpBuff.Length);

            tmpBuff = null;
        }
        catch (Exception exp)
        {
            System.Diagnostics.Debug.WriteLine(exp.Message);
        }

        return fileExtension;
    }

and still i got this error :
Unable to load DLL 'libmagic-1': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

@hey-red
Copy link
Owner

hey-red commented Apr 9, 2017

Hmm, it's very strange. Which windows version you are using? 32 or 64 bit?
Off course I should've be test it with full .net framework.

@patachi
Copy link
Author

patachi commented Apr 9, 2017

win 10 x64

@hey-red
Copy link
Owner

hey-red commented Apr 9, 2017

Ok, I have same system.
It seems that problem is that DLL is not copied to output directory.

@hey-red
Copy link
Owner

hey-red commented Apr 10, 2017

@patachi It's seems like i'm solve that problem. Update package and you will need to set platform x64 in your application.

@patachi
Copy link
Author

patachi commented Apr 10, 2017

yup it works fine
thanks @hey-red

@hey-red hey-red closed this as completed Apr 11, 2017
@sacerdotu
Copy link

@hey-red Last version (2.3.0) not working for AnyCPU platform.
Current configuration:
Win 10, x64
VS 2017, Platform: AnyCPU

@hey-red
Copy link
Owner

hey-red commented May 30, 2017

@sacerdotu change platform to x64.

@sacerdotu
Copy link

@hey-red But I need anycpu :) If I change to x64 it will work for sure.

@sacerdotu
Copy link

sacerdotu commented May 30, 2017

@hey-red This is an issue that should be fixed

at HeyRed.Mime.MagicNative.magic_open(MagicOpenFlags flags)
at HeyRed.Mime.Magic..ctor(MagicOpenFlags flags, String dbPath)
at HeyRed.Mime.MimeGuesser.GuessMimeType(String filePath)
at HeyRed.Mime.MimeGuesser.GuessFileType(String filePath)
at MimeHelper.Program.Main(String[] args) in C:\Users\sacerdotu\documents\visual studio 2017\Projects\MimeHelper\MimeHelper\Program.cs:line 28

@hey-red
Copy link
Owner

hey-red commented May 30, 2017

Currently there is no x86 support. Maybe later i'm trying to build 32-bit libmagic, and АnyCPU will be works by default.

@sacerdotu
Copy link

Perfect. Waiting for the new version!

@sacerdotu
Copy link

@hey-red Any news?

@himadrinath
Copy link

@hey-red uploaded to azure change the application setting to 64bit but problem not solved.
getting this

mime_1

check the server

mime_2

but locally its working fine.. what is happening can u help me?

@hey-red
Copy link
Owner

hey-red commented Nov 7, 2017

@himadrinath
I did not work with azure, but if your app is self contained(contains all dependencies in working dir), then you need to copy libmagic and and other files from win runtime into directory that contains your app.

@himadrinath
Copy link

@hey-red i did now i am getting another error

An unhandled exception occurred while processing the request.

BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

@hey-red
Copy link
Owner

hey-red commented Nov 7, 2017

Your VM under linux or windows?

@himadrinath
Copy link

@hey-red windows

@himadrinath
Copy link

@hey-red
Copy link
Owner

hey-red commented Nov 7, 2017

Yep, its seems like app run in x86 mode. Also, by default azure VM uses x64 windows?
Change target platform to x64 and publish your app again.

@himadrinath
Copy link

@hey-red working on it. lets see what happen. i will inform you the result

@himadrinath
Copy link

@hey-red i changed the runtime to win-x64 and deploy to azure now its working fine. thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants