Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

HoloLens 1 HTTPClient Connect Failure

Discussion in 'Scripting' started by sebplus, Jun 4, 2020.

  1. sebplus

    sebplus

    Joined:
    Mar 7, 2018
    Posts:
    4
    I'm experiencing a quite odd issue (or at least to me). I have built a HoloLens Application with Unity 2019.3 and MixedReakity Toolkit 2.0.0-RC.2.1. From within the app I'm doing some requests against a webservice. I'm using System.Net.Http.HttpClient, which get send as a row of Tasks like

    Code (CSharp):
    1. await RequestAndSaveToken();
    2. await RequestAndSaveDownload();
    3. await Unzip();
    4. await DownloadResources();
    as each Task is dependent on the other.
    All of this was working fine, but somehow I must have changed something, somewhere in my configuration (I know this is a bit vague), that now I always recieve a WebException with Status 2 (Connect Failure) when running the app on our HoloLens 1. In Unity Editor, when running the Game everything is working fine and even my old version is still getting a connection to the webservice.
    My guess is, that it must have to something with the UWP solution which I build out of Unity. I tried API Compability Level .NET 2.0 and 4.0, built for Visual Studio 2017 and 2019. I have the permissions for InternetClientServer.
    I also tried using UnityWebRequest, which successfuly gets a response. But I would like to keep using my solution with Tasks and HTTPClient.
    Does anyone have an idea or a hint which might cause this issue, as it is a bit annoying and time consuming to build unity player, build the uwp and deploy over and over again.
    Thank you very much!
     
    Last edited: Jun 4, 2020
  2. LSRad

    LSRad

    Joined:
    Aug 14, 2019
    Posts:
    4
    Running into the same issue.

    Unity 2019.3.1

    New project with HttpClient.GetAsync / HttpClient.SendAsync will result in "system.net.webexception: error: connectfailure (value does not fall within the expected range.)" when running on the hololens 1 after il2cpp.

    All works in editor.

    This used to work couple of months ago when we were testing with previous versions.
     
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I haven't used the HoloLens for quite a while now, especially not with more recent versions of Unity and the MRTK.

    But the first things to check are the capabilities for internet access in the settings (somewhere in the editor or in the manifest file). Just like some other platforms, it'll ask for permission for all required capabilities when you start a newly deployed app.
     
  4. LSRad

    LSRad

    Joined:
    Aug 14, 2019
    Posts:
    4
    In my case, InternetClient, InternetClientServer, and PrivateNetworkClientServer are all enabled and the OP also mentioned that he got InternetClientServer permissions.
     
  5. sebplus

    sebplus

    Joined:
    Mar 7, 2018
    Posts:
    4
  6. sebplus

    sebplus

    Joined:
    Mar 7, 2018
    Posts:
    4
    @LSRad: I've just built my project on Unity 2019.3.1f1 and Microsoft Visual Studio Community 2017 (Version 15.5.2 VisualStudio.15.Release/15.5.2+27130.2010 Microsoft .NET Framework Version 4.8.03752) and I got a connection. After that I tried building in Unity 2019.3.15f and again Visual Studio Community 2017 and againt it worked,
    Which Visual Studio version are you using?
     
    Last edited: Jun 6, 2020
  7. LSRad

    LSRad

    Joined:
    Aug 14, 2019
    Posts:
    4
    Thanks for the updates!

    My current setup is:
    • Microsoft Visual Studio Professional 2019 Version 16.6.0. Also tried with few older versions of 2019.
    • Unity 2019.3.15f
    • Unity 2019.3.1f1
    • Unity 2018.4.23f1
    Non of them worked.
     
  8. LSRad

    LSRad

    Joined:
    Aug 14, 2019
    Posts:
    4
    Ok so I finally got HttpClient to work. Not 100% sure what made it but my guess is uninstalling SDK version 10.0.19041.0.

    Before that I was trying with VS 2017 15.9.23, VS 2019 16.6.0/16.6.1 with Unity 2019.3.1, 2019.3.1f1, 2018.4.23f1. I was explicitly setting the Unity build to use SDK version 10.0.18362.0 but non of them worked.

    Now all combination seem to work. But like I said it might have been one of the other hundred things I tried.

    @sebplus, @Suddoha - thanks for the help.
     
    Kevin-Baptista likes this.
  9. rdivossen

    rdivossen

    Joined:
    Jul 13, 2020
    Posts:
    1
    I can confirm that this error can be solved by uninstalling SDK version 10.0.19041.0
    Thanks so much for your post. This problem has cost me several hours.