Creating HoloLens applications is just cool! But connecting them to services in the Cloud makes it even cooler. Think of provisioning information on real-life objects or straw through Cloud data like persons, related contacts, documents and other stuff. This allows you to build rich applications containing information you normally process in a 2D world  like your browsers. By extending it to a 3D world, you are able to process the data in a completely different way. Think of creating teams of people within your organization and group them based on specialties, getting a more clear inside view of your site structure in SharePoint or have a 3D model of the Microsoft Graph entities related objects.

This article is split into several posts which together describes how to connect your HoloLens App with the Microsoft Graph.

  1. Introduction 
  2. Register, Connect and get data
  3. Reference your class library in Unity (this post)
  4. Create a scene in Unity and connect your library

Referencing a class library

In the previous post we wrote code to authenticate against Azure AD v2.0 endpoint and retrieved data from the Microsoft Graph inside our OfficeGraphLibrary Class Library.

We want to use this class library in our HoloLens application. It would be logical to reference the class library directly in the generated Visual Studio solutions by Unity. But that will give you issues when you try to compile.

NU1201 Project OfficeGraphLibrary is not compatible with uap10.0.10240 (UAP,Version=v10.0.10240). Project OfficeGraphLibrary supports: uap10.0.10586 (UAP,Version=v10.0.10586)

Unity allows you to use Universal Windows Platform specific plugins like out OfficeGraphLibrary class library. They will work when the plugin is only used for the Universal Windows Platform. If you also want to use the same plugin in the Unity Editor you will need to setup a placeholder. A placeholder is nothing more than a second plugin containing the same methods but only contains code which is allowed within the Unity Editor. Both plugins need to share the same name, assembly version and methods. How to accomplish this is explained here.

In our case we only want to have it work for the Universal Windows Platform.

Capture

Therefor we need to create a folder structure under assets where to store the class library and referencing dlls. The structure is as follow: Assets –> Plugins –> WSA. In that folder we need to copy the class library. You can do that by hand or use a Post-build event command line in the Build events settings page of the OfficeGraphLibrary class library. The command could be something like this:

copy /Y "$(TargetDir)\$(TargetName).dll" "c:\hololens\OfficeSketch\Assets\Plugins\WSA\$(TargetName).dll"

Unity will notice any changes made to files and folders within the Assets folder structure and updates when necessary. As soon as you focus the Unity application it updates.

Secondly we need to configure the settings of the asset in Unity. Click on the class library and make sure that the following settings are met.

Capture

Select the “WSAPlayer” as one of the platforms. You will get the second part containing the platform specific settings. Make sure that SDK  is set to UWP , ScriptingBackend to Dot.Net and that the option Don’t process is selected. That last option only applies to managed assemblies and is only needed when for example your code contains classes which need to be serialized for Unity.

In our case we are also making use of the Newtonsoft.Json.dll library. This is because we have include the NuGet package names Microsoft.Graph which is depending on that library. Compiling the code will cause Unity to give an error.

ArgumentException: The Assembly Newtonsoft.Json is referenced by OfficeGraphLibrary (‘Assets/Plugins/WSA/OfficeGraphLibrary.dll’). But the dll is not allowed to be included or could not be found.

That means we need to add the Newtonsoft.json.dll library to the same folder in Unity with the same settings.

Now try to rebuild from Unity and you will notice it smoothly generates the Visual Studio solution for you. You will notice when you reload your solution in Visual Studio that the library references are included.

Capture

Previous articleConnecting your HoloLens app with Microsoft Graph – Register, connect and get data – 2 of 4
Next articleInterview by vlogger Erwin Jongsma about HoloLens
A professional which inspires, motivates and educates businesses on how to leverage emerging technologies using Virtual, Augmented and Mixed Reality in their journey to digital innovation. He has a strong background on SharePoint, Office 365 and Microsoft Azure and is working with machine learning, artificial intelligence and cognitive services. Primarily focused on manufacturing, construction, industry, logistics and maritime/offshore, his goal is helping businesses to achieve more on creating, improving, smartening and shortening of business processes by using services, apps and devices. Furthermore, he engages in speaking, blogging and is organizer of events like the Mixed Reality User Group, Mixed Reality Talk @ VR, SP&C and the Global AI/MR Bootcamp. With more than 20 years of IT Business experience, acting in different roles like solution architect, he believes the future is just starting! Highly experienced in all realities, HoloLens and other devices, User experiences on devices and connecting the world to the cloud will help him to shape that future!

7 COMMENTS

Leave a Reply to Connecting your HoloLens app with Microsoft Graph – Register, connect and get data – 2 of 5 – AppzInside Cancel reply

Please enter your comment!
Please enter your name here