takuya-takeuchi/DlibDotNet

create detector issue

shouwei opened this issue · 4 comments

Hi there,

I am trying to get landmarks 68 from an input image. But always get exceptions when creating the detector.

Environment

Win10 64 + VS 2022
DlibDotNet 19.21.0.20220429

Here is the code snippet:

static void Main(string[] args)
{
    try
    {
        var detector = Dlib.GetFrontalFaceDetector();  // The type initializer for 'DlibDotNet.NativeMethods' threw an exception.
        using (var sp = ShapePredictor.Deserialize(args[0]))
        {
        }
   }
}

Output:

The type initializer for 'DlibDotNet.NativeMethods' threw an exception.
Press any key to continue . . .

could you check detail of exception?
you can see in visual studio watch expression.
I guess you have ti install c++ runtime.

Here is all the information for exception detail:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.TypeInitializationException: The type initializer for 'DlibDotNet.NativeMethods' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at DlibDotNet.NativeMethods.LossMetric_anet_type_create()
at DlibDotNet.NativeMethods..cctor()
--- End of inner exception stack trace ---
at DlibDotNet.NativeMethods.get_frontal_face_detector()
at FaceConstructor.Form1.button1_Click(Object sender, EventArgs e) in D:\dev\second_year\FaceConstructor\Form1.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll

FaceConstructor
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/dev/second_year/FaceConstructor/bin/Release/FaceConstructor.exe

System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

System
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4488.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll

System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll

System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll

Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll

DlibDotNet
Assembly Version: 19.21.0.0
Win32 Version: 19.21.0.0
CodeBase: file:///D:/dev/second_year/FaceConstructor/bin/Release/DlibDotNet.DLL

netstandard
Assembly Version: 2.0.0.0
Win32 Version: 4.8.4084.0
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/netstandard/v4.0_2.0.0.0__cc7b13ffcd2ddd51/netstandard.dll

System.Runtime.InteropServices.RuntimeInformation
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.InteropServices.RuntimeInformation/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Runtime.InteropServices.RuntimeInformation.dll

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

please check build option of visualstudio
I think you make enable prefer 32bit flag.

Cool! you are right!

The default project created by VS .NET framework is targeted "Any CPU", and "Any CPU" by default is Win32.
After creating a new platform with x64, it works correctly now.

Highly appreciate your help!