Use System.Net.Http library with Unity in a Hololens App project

Use System.Net.Http library with Unity in a Hololens App project

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


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 ()
	// 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.

This Post Has 5 Comments

  1. ninjapretzel

    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’

    1. Alexander Meijers

      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. annam

    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?

    1. Alexander Meijers

      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. Bradford Brown

    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