gpt4 book ai didi

c# - 在 HoloLens 1 上,在使用默认构造函数 "ArgumentException: Value does not fall within the expected range"创建 TcpClient 对象时抛出

转载 作者:行者123 更新时间:2023-12-03 11:50:59 29 4
gpt4 key购买 nike

直到大约 2 天前,我有一个应用程序运行良好,其中 HoloLens 1 通过 TCP 连接到本地网络上的另一台 PC。

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

我尝试了以下解决方案,有人在 HoloLens slack 上链接给我: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项目(哪个版本似乎无关紧要)

在场景中添加一个GameObject,附上:

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 build设置,确保在发布设置 > 功能中包括 InternetClient、InternetClientServer、PrivateNetworkClientServer。

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

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

最佳答案

看起来这是 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)
{

关于c# - 在 HoloLens 1 上,在使用默认构造函数 "ArgumentException: Value does not fall within the expected range"创建 TcpClient 对象时抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62314810/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com