2

I planned to work with two Kinects. I have installed VS C#, SDK 1.8 and 2.0, of Kinect, and my issue is:

After adding one reference library (ex. 1.8), it is not possible to add the another (ex. 2.0, message "the reference... already exists"). I perceived that is due to the names of namespaces and classes are the same. So, I cannot instantiate the second sensor,

Please, suggest me what can I do to resolve it, specifically if there is any way to access the different versions of the same resource (ex. KinectSensor class in version 1.8 and 2.0)?

Carl
  • 113
  • 1
  • 14

1 Answers1

1

There are several solutions to your problem. The first one (probably the most naive), is to create two different projects, each of which has a different reference. Then you can write a third layer that uses data provided from the first two projects.

If you really need to use both the references in the same project, there is however another option, and it consists in using extern aliases.

First of all, add a single reference (for instance, Microsoft.Kinect, version 1.8). Then, save your project and close Visual Studio. In the project folder, you should find a .csproj file, that you can open with a text editor. Looking at its content, you will find a line like this:

<Reference Include="Microsoft.Kinect, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

Now, change the above line with the following ones:

<Reference Include="Microsoft.Kinect, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <Aliases>KinectV1</Aliases>
</Reference>
<Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <Aliases>KinectV2</Aliases>
</Reference>

You should see now both references in the same project, also when you open it with Visual Studio.

Then you should be able to use something like this:

// You must declare aliases here:
extern alias KinectV1;
extern alias KinectV2;

// Then some using...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// ... and do not forget Kinect!
using KinectV1;
using KinectV2;

// Now you can do something like this:
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Something from Microsft.Kinect V2
            KinectV2.Microsoft.Kinect.HandState hs = KinectV2.Microsoft.Kinect.HandState.Closed;

            // Something from Microsft.Kinect V1
            KinectV1.Microsoft.Kinect.Skeleton s = new KinectV1.Microsoft.Kinect.Skeleton();
        }
    }
}

If your project does not compile, try to close Visual Studio and delete the hidden .suo file (in the same folder of the .sln file of your project).

Take a look to this answer if you have any more troubles.

Community
  • 1
  • 1
Vito Gentile
  • 13,336
  • 9
  • 61
  • 96
  • Hi Vito Gentile, I resolved my issue by using the extern alias of DLLs. Thanks. – Carl Mar 09 '16 at 23:04
  • Thanks for this, I tried this using VS2012 and I've got it to work. It's worth noting that my second reference still had the yellow triangle next to it suggesting it hadn't worked. I was scratching my head for ages until I just pressed ahead anyway with the 'extern alias' etc. Intellisense got a little upset but in the end all's working fine using this solution! – Wiredchop Jul 06 '16 at 16:14