Search code examples
c#dllvisual-studio-2013kinectkinect-sdk

Packaging folders with .dll's for Kinect 2.0


I'm just getting in to Kinect 2 programming here and right now I'm having some issues with the HighDefinitionFace stuff. I have a really simple C# program that is just supposed to start the Kinect camera, tell me that it's started, and then output the hair color of the subject, like so:

    static class Program
    {
        static KinectSensor mySensor = null;
        static HighDefinitionFaceFrame frames = null;
        static HighDefinitionFaceFrameSource frameSource = null;
        static HighDefinitionFaceFrameReader frameReader = null;

    public static void Main() 
    {
        mySensor = KinectSensor.GetDefault();
        mySensor.Open();

        System.Console.WriteLine(mySensor.IsAvailable);

        frameSource = new HighDefinitionFaceFrameSource(mySensor);
        frameReader = frameSource.OpenReader();
        frames = frameReader.AcquireLatestFrame();

        System.Console.WriteLine(frames.FaceModel.HairColor);
    }
    
}

Everything works fine until I try to initialize frameSource, then it throws an InvalidOperationException:

An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.Kinect.Face.dll

Additional information: This API has returned an exception from an HRESULT: 0x80070002

with two inner exceptions referencing misplaced files that cannot be found. I think the issue is based on the following line from the Microsoft API reference:

Every application that uses Microsoft.Kinect.Face.dll must be packaged with the NuiDatabase folder that shipped with Microsoft.Kinect.Face.dll. The face dll is only guaranteed to work with the specific NuiDatabase folder that it shipped with. The face APIs are designed to load database files from the NuiDatabase folder upon initialization and will look for the folder in the same location as Microsoft.Kinect.Face.dll.

So, my question is, how to I make sure that this NuiDatabase folder is accessible with the .dll?

Stuff I've tried:

-The Kinect SDK 2.0 contains about five instances of Microsoft.Kinect.Face.dll in different directories, each with a NuiDatabase folder in the same directory. All these .dll's and NuiDatabase folders appear to be identical. I've tried setting each of these .dll's as the references, and they all gave the same result.

-Creating a local NuGet package containing the .dll and the NuiDatabase folder and adding it to the project. I've tried it both with and without the .dll in its own Lib folder. It correctly references Microsoft.Kinect.Face and allows me to declare all the required types, but it still throws the same error at the same line.

Any other suggestions, or anything I could have maybe missed in my setup?


Solution

  • I ended up using a pre-made NuGet package available at https://www.nuget.org/packages/Microsoft.Kinect.Face.x64/.

    Adding this package to my project solved the problem.