2

I am deploying a unity build into HoloLens I do not know why I am getting this error, it works fine on Unity editor but when deploying to HoloLens it throws the following error:

ArgumentException: Value does not fall within the expected range.

System.Net.Sockets.Socket.SetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, System.Int32 optionValue)

This is my piece of code

 try {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(apiURL);
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "application/json";
                using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()
))
                    streamWriter.Write("{ \"config\": { \"languageCode\" : \"en-US\" }, \"audio\" : { \"content\" : \"" + file64 + "\"}}");
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

After debugging I've determined this is the line that is throwing the error

httpWebRequest.GetRequestStream()

Please can anyone help!?!

Antonio
  • 29
  • 2
  • Could you double-check the following Capabilities have been checked in Publishing Settings > Capabilities: InternetClient, InternetClientServer, PrivateNetworkClientServer. Because according to your error message, it seems to be your app does not successfully connect to the server. – Hernando - MSFT Jul 13 '20 at 07:45
  • Besides, We found this thread points out that the mismatched version of Windows SDK may also cause this issue: https://stackoverflow.com/questions/62314810/on-a-hololens-1-when-creating-tcpclient-object-with-default-constructor-argume Therefore, it is worth trying to set Build Settings > Target SDK version to 10.0.17763.0. – Hernando - MSFT Jul 13 '20 at 07:45

1 Answers1

1

Regarding the issue as Socket connect causes the ArgumentException: Value does not fall within the expected range. error. We have confirmed that this is a tracking Unity bug internally and should has pushed a fix. And there is already a discussion in Unity forum: https://forum.unity.com/threads/il2cpp-failing-in-windows-machine.891436/#post-5944052

You can try to verify the latest Unity 2019.4.x version to see if the fix has been merged or check the workaround in the above community discussion.

Franklin Chen - MSFT
  • 4,845
  • 2
  • 17
  • 28