在HoloLens 1上,使用默认构造函数“ ArgumentException:值不在期望范围内”创建TcpClient对象时,抛出

问题描述 投票:-1回答:1

直到大约两天前,我的应用程序都能正常工作,其中HoloLens 1通过TCP连接到本地网络上的另一台PC。

最近,每次对TcpClient()默认构造函数的调用都会引发上述错误。没有值传递给它(因为它是默认值),因此我不知道它在哪个值上出错。

我尝试了以下解决方案,由HoloLens松弛人员联系到我:https://github.com/Azure/azure-remote-rendering/issues/6

该解决方案需要更新到Unity 2019.3.15f。我已经尝试了Visual Studio,Windows SDK和Unity的多种不同配置。

我发现了其他多个帖子,这些帖子似乎表明罪魁祸首是il2cpp。这是相关输出的副本。

UnloadTime: 7.610200 ms
Exception thrown at 0x771E3AE2 in TCPTest.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x025CE7EC.
Exception thrown at 0x771E3AE2 in TCPTest.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x025CE90C.
ArgumentException: Value does not fall within the expected range.
  at System.Net.Sockets.Socket.SetSocketOption (System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, System.Int32 optionValue) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.Socket.set_DontFragment (System.Boolean value) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.Socket.SocketDefaults () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.TcpClient.initialize () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.TcpClient..ctor (System.Net.Sockets.AddressFamily family) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Net.Sockets.TcpClient..ctor () [0x00000] in <00000000000000000000000000000000>:0 
  at TcpTestClient.Start () [0x00000] in <00000000000000000000000000000000>:0 

(Filename: currently not available on il2cpp Line: -1)

到目前为止,我所产生的此错误的最小发生量是:

新的Unity项目(似乎与哪个版本无关)

将游戏对象添加到场景,附加:

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

public class TcpTestClient : MonoBehaviour
{
    private TcpClient tcpClient;
    // Start is called before the first frame update
    void Start()
    {
        tcpClient = new TcpClient();
        if (tcpClient != null)
        {
            Debug.Log("Constructor succeeded!");
        }
    }
}

配置为HoloLens 1指定的Unity构建设置,确保在发布设置>功能中包括InternetClient,InternetClientServer,PrivateNetworkClientServer。

使用已安装的适当构建工具在Visual Studio 2017或2019中构建,打开结果解决方案。部署到HoloLens,结果错误将输出到调试控制台。

感谢您的阅读,我非常感谢任何人的见解。

c# sockets unity3d hololens il2cpp
1个回答
0
投票

看来这是Unity中的错误。看到此:https://forum.unity.com/threads/il2cpp-failing-in-windows-machine.891436/#post-5944052

解决方法涉及更改il2cpp源代码:

diff --git a/libil2cpp/os/Win32/SocketImpl.cpp b/libil2cpp/os/Win32/SocketImpl.cpp
index f63abecd5..5821d2577 100644
--- a/libil2cpp/os/Win32/SocketImpl.cpp
+++ b/libil2cpp/os/Win32/SocketImpl.cpp
@@ -1700,11 +1700,7 @@ namespace os
                 break;

             case kSocketOptionLevelIP:
-#ifdef SOL_IP
-                *system_level = SOL_IP;
-#else
                 *system_level = IPPROTO_IP;
-#endif

                 switch (name)
                 {
@@ -1777,11 +1773,7 @@ namespace os
                 break;
 #if IL2CPP_SUPPORT_IPV6
             case kSocketOptionLevelIPv6:
-        #ifdef SOL_IPV6
-                *system_level = SOL_IPV6;
-        #else
                 *system_level = IPPROTO_IPV6;
-        #endif

                 switch (name)
                 {
© www.soinside.com 2019 - 2024. All rights reserved.