Closed solrac3f closed 5 months ago
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Hey there, thanks for the report!
I kinda doubt this is specific to .NET MAUI to be honest. If you create a WinUI app (without MAUI) does it work then? Would you be able to try that and verify?
You mention it does work for a WinForms app?
Yes, with WinForms app it works. I will try a WinUI app (without MAUI).
Please let us know the result!
That WinForms app does that run on the same .NET version? .NET 8? Or is that still .NET Framework? Can you maybe provide some more version information?
Yes the WinForms app runs on .NET 8. I created a WinUI app without MAUI. Like in the WinForms app it is working. The app runs on a Windows 10 Machine
Follows the code for the WinUI app:
using System;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App2
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await SendCommand("O");
}
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
await SendCommand("F");
}
private async Task SendCommand(string command)
{
ClientWebSocket socket = new ClientWebSocket();
try
{
await socket.ConnectAsync(new Uri("ws://192.168.0.2:80/command"), CancellationToken.None);
byte[] buffer = Encoding.UTF8.GetBytes(command);
await socket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
Trace.WriteLine("Incoming message: " + command);
// Receive response if needed
var responseBuffer = new byte[1024];
var response = await socket.ReceiveAsync(new ArraySegment<byte>(responseBuffer), CancellationToken.None);
var responseMessage = Encoding.UTF8.GetString(responseBuffer, 0, response.Count);
}
catch (Exception ex)
{
Console.WriteLine("Error", $"Error: {ex.Message}", "OK");
}
finally
{
if (socket.State == WebSocketState.Open || socket.State == WebSocketState.Connecting)
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closed by the client", CancellationToken.None);
socket.Dispose();
}
}
}
}
@solrac3f can you share the full stack trace of the exception?
Hi @solrac3f. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.
Description
Using the following code in a .NET Form app. A Websocket connection to a Server is established and the commands are send correctly and received correctly on the server side.
Using the same code in a .NET MAUI app a Exception Error is thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
No response