DlibDotNet icon indicating copy to clipboard operation
DlibDotNet copied to clipboard

Can't load DlibDotNetNativeDnn in Blazor WebAssembly project

Open alexsosa2000 opened this issue 2 years ago • 0 comments

Summary of your issue

I'm trying to use DlibDotNet in a Blazor WebAssembly project and I'm getting DllNotFoundException: DlibDotNetNativeDnn. I think this may be because DlibDotNet doesn't have a wasm build.

I'm basically getting an image from the user, detecting the face with Dlib, and drawing a rectangle. But when I call Dlib.GetFrontalFaceDetector(), it throws the exception.

The same code works in a console app running in the same machine.

Environment

Blazor WebAssembly (.NET) DlibDotNet nuget package v19.21.0.20220724

Example code:

To repro:

  • Create a Blazor WebAssembly project
  • Add a package reference to DlibDotNet
  • Add the following code to a page / component:
using (var fd = Dlib.GetFrontalFaceDetector())
{
	var img = Dlib.LoadPng<RgbPixel>(imgArray);

	// find all faces in the image
	var faces = fd.Operator(img);

	return faces;
}
  • Launch in the browser so it executes this code
  • You'll see an error in the console (DevTools - F12)

Output:

Error: System.TypeInitializationException: The type initializer for 'DlibDotNet.NativeMethods' threw an exception.
 ---> System.DllNotFoundException: DlibDotNetNativeDnn
   at DlibDotNet.NativeMethods..cctor()
   --- End of inner exception stack trace ---
   at DlibDotNet.Dlib.GetFrontalFaceDetector()

alexsosa2000 avatar Jul 06 '23 17:07 alexsosa2000