sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.62k stars 1.65k forks source link

Operation is not supported on this platform. #652

Open yuzhupeng opened 3 years ago

yuzhupeng commented 3 years ago

Operation is not supported on this platform. ???what problem

yuzhupeng commented 3 years ago

log:

{ "system": "Meowv.Blog", "datetime": "2021-02-24 23:00:24,733", "description": "binance:System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Action1.BeginInvoke(T obj, AsyncCallback callback, Object object) at WebSocketSharp.WebSocket.open() in C:\Users\Administrator\Desktop\chenxu\websocket-sharp\WebSocket.cs:line 1554 at WebSocketSharp.WebSocket.Connect() in C:\Users\Administrator\Desktop\chenxu\websocket-sharp\WebSocket.cs:line 3235 at GetTradeHistoryData.binanceWebscoket.Start(String senddata) in C:\Users\Administrator\Desktop\chenxu\GetTradeHistoryData\Futures\BINANCE\binanceWebscoket.cs:line 104", "level": "ERROR", "info": "" } { "system": "Meowv.Blog", "datetime": "2021-02-24 23:00:25,725", "description": ":System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Action1.BeginInvoke(T obj, AsyncCallback callback, Object object) at WebSocketSharp.WebSocket.open() in C:\Users\Administrator\Desktop\chenxu\websocket-sharp\WebSocket.cs:line 1554 at WebSocketSharp.WebSocket.Connect() in C:\Users\Administrator\Desktop\chenxu\websocket-sharp\WebSocket.cs:line 3235 at GetTradeHistoryData.binanceUSDWebscoket.Start(String senddata) in C:\Users\Administrator\Desktop\chenxu\GetTradeHistoryData\Futures\BINANCE\binanceUSDWebscoket.cs:line 101", "level": "ERROR", "info": "" } { "system": "Meowv.Blog", "datetime": "2021-02-24 23:02:03,656", "description": "binancewebsocket_Closed", "level": "ERROR", "info": "" } { "system": "Meowv.Blog", "datetime": "2021-02-24 23:02:04,049", "description": "binancewebsocket_Closed", "level": "ERROR", "info": "" } { "system": "Meowv.Blog", "datetime": "2021-02-24 23:03:08,490", "description": ":System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Action`1.BeginInvoke(T obj, AsyncCallback callback, Object object) at WebSocketSharp.WebSocket.open() in C:\Users\Administrator\Desktop\chenxu\websocket-sharp\WebSocket.cs:line 1554 at WebSocketSharp.WebSocket.Connect() in C:\Users\Administrator\Desktop\chenxu\websocket-sharp\WebSocket.cs:line 3235 at GetTradeHistoryData.binanceWebscoket.Start(String senddata) in C:\Users\Administrator\Desktop\chenxu\GetTradeHistoryData\Futures\BINANCE\binanceWebscoket.cs:line 104", "level": "ERROR", "info": "" }

BossOfGames commented 3 years ago

Are you by chance using .NET Core? I noticed that this issue is specifically related to the fact this project wasn't compiled against Core. I have no problems using .NET Standard.

PhilippElhaus commented 3 years ago

I have this too in .NET 5 WPF

davlovsky commented 2 years ago

Same here. Winforms, after migrating from .NET Framework to .NET 5.

PhilippElhaus commented 2 years ago

Switched to the latest NuGet of WebSocket4Net - is similar to code and works just fine.

davlovsky commented 2 years ago

I had this line in my old code: Websocket.SslConfiguration.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

Do you know if there is a WebSocket4Net analog?

henon commented 2 years ago

One workaround is to use Connect instead of ConnectAsync and Send instead of SendAsync and if that doesn't work for you switch to https://github.com/sipsorcery/websocket-sharp

acd450 commented 5 months ago

With a .Net6 project, I used Close instead of CloseAsync and no longer had this error. Using Connect and Send as well, thanks to @henon.