One of the things we normally couldn’t use was functionality from the System.Net.Http library. The reason was very simple. This library was not supported in .NET 3.5 framework. Since Unity 2017 we are able to use on an experimental basis the .NET 4.6 framework. Or actually an equivalent of it.

The following steps explain how to make use of the System.Net.Http classes.

For this scenario i’m using the following versions of tools:

  • Visual Studio Enterprise 2017 Version 15.4.2
  • Unity Version 2017.2.0f3

Setup an Unity project and do your standard HoloLens project settings. Create a simple scene with for example a GameObject. Make sure that the camera is configured, the XR settings in Player settings set.

Go to Player Settings –> Settings for Universal Windows Platform –> Other Settings

Capture

Make sure that Scripting Runtime Version is set to Experimental (.NET 4.6 Equivalent) and Api Compatibility Level to .NET 4.6. Keep in mind that this setting is currently in development. Hence the term experimental.

You do not need to copy the dll to the plugins folder under assets. The System.Net.Http version 4.00 is supported and is automatically loaded from the following location:

C:\Program Files\Unity2017\Editor\Data\MonoBleedingEdge\lib\mono\gac\System.Net.Http

Add a GameObject to your scene and add the script below to have it part of the scene.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net.Http;

public class ServiceConnect : MonoBehaviour {

	// Use this for initialization
	void Start ()
    {
        TestMethod();
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    async void TestMethod()
    {
        HttpClient client = new HttpClient();
        string result = await client.GetStringAsync("some url");
    }
}

The script itself does not so much but gives you an impression of calling the HttpClient method which is part of the System.Net.Http library from the Start().

Build the Visual Studio solution from Unity. You will notice that no errors occur. Secondly build and deploy the solution to your HoloLens device from Visual Studio.

Previous articleConnecting your HoloLens app with Microsoft Graph – Create a scene in Unity and connect your library – 4 of 4
Next articleHave persistence across multiple Unity scenes using spatial anchors
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!

5 COMMENTS

  1. As of Unity 2017.3.0f3, this no longer seems to work, unfortunately.
    I have both configurations set to 4.6, and I can make use of Async Tasks and the C# 6.0 language features, but for some reason, the System.Net.Http namespace is unavailable.

    I have the DLL in the Unity install folder as well, but can’t drag it into the project under Assets/Plugins/ to force a reference to it. Doing so gives me:

    Error: System.BadImageFormatException:
    File name: ‘Assets/Plugins/DLL/System.Net.Http.dll’

    • Currently i did a post on doing web request stuff outside Unity with a separate UWP DLL. My recommendation at the moment is go for that instead of using this stuff directly inside Unity. Unity versions are following up quickly and causing by the version issues within HoloLens applications.

  2. Thanks for your blog/article. I would like to use system.speech dll in unity project. Should I copy syste.speech.dll into assets folder and reference it in .sln file?

    Is there any other way to do it?

    • You could that. But you need to know if there are dependencies on other DLLs and see if they are allowed to be used in an UWP (Universal Windows App)

  3. Hello, my name is Bradford Brown and I am a student working on a design project to stream an ip camera into unity from a raspberry pi. I created a plug-in with Unity using .NET 3.5 framework but whenever i try to build my solution with this code

    public void GetVideo(){
    texture = new Texture2D(2, 2);
    // create HTTP request
    HttpWebRequest req = (HttpWebRequest) WebRequest.Create( sourceURL );
    //Optional (if authorization is Digest)
    req.Credentials = new NetworkCredential(“username”, “password”);
    // get response
    WebResponse resp = req.GetResponse();

    I get error GetResponse() is not present, do you have any idea how I can get around this?

    I saw your other post about using compiler directives but I do not understand how to implement it.

    Please advise

Leave a Reply to annam Cancel reply

Please enter your comment!
Please enter your name here