I'm currently having an issue using Web Socket Client in .NET 4 in Unity in UWP builds using the IL2CPP backend. The Unity version I'm running is 2018.2.17f1. When I run my app without Visual Studio Debugging (so opening the solution in VS 2017 and hit Build > Start Debugging) it disconnects from the Web Socket Server fine and no error is thrown in the Unity logs. But when I build the project then open the generated solution file and click "Local Machine" or click Build > Start Debugging I get the following exception thrown in the output window: `Exception thrown at 0x00007FFAE19BDCEA (ntdll.dll) in Sensei.exe: 0xC0000008: An invalid handle was specified.` in the SocketImpl.cpp file on line 1810. But just in case it's different for other people, it's this block of code:
__try
{
affected = select(0, &rfds, &wfds, &efds, timeoutPtr); // Breaks on this line
}
__except (SocketExceptionFilter(GetExceptionCode()))
{
}
My Web Socket Client is encapsulated in a class so it's more portable in my code but the C# code for disconnecting in that class looks like this:
public async void Disconnect(WebSocketCloseStatus status, string reason)
{
await DisconnectAsync(status, reason);
}
private async Task DisconnectAsync(WebSocketCloseStatus status, string reason)
{
try
{
await _webSocket.CloseAsync(status, reason, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception e)
{
Debug.LogWarning("Exception thrown when disconnecting to WebSocket. " + e.Message);
}
finally
{
_webSocket.Dispose();
}
}
I've been working on this for the last two days but haven't gotten a clue as to why it's doing this. Before I had implemented WebSocket-sharp but it gave me the same issue I'm having now. It broke at the same point in my code and gave the same exception. My other client (that I'm connecting to through a Web Socket Server) is on Android running IL2CPP with the same code and it doesn't seem to break. I also ran this on Unity Standalone for Windows x86_64 with the IL2CPP backend, it also doesn't seem to break. Is this the expected behaviour and that I shouldn't run Unity UWP in Visual studio or is there something I'm doing wrong here?
↧