Bug 58026 - Unusual problem with System.Net.WebSockets
Summary: Unusual problem with System.Net.WebSockets
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: PC All
: --- normal
Target Milestone: Future Release
Assignee: Bugzilla
Depends on:
Reported: 2017-07-08 00:31 UTC by Paul
Modified: 2017-09-12 11:46 UTC (History)
5 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Paul 2017-07-08 00:31:27 UTC
Good day all I am not sure if I should report this or not, I wrote a very simple c# program, no windows forms or other weirdness, simply a threaded websocket proxy in visual studio on windows; all works happy.

Now when I export the executable to my FreeBSD box running:
Mono JIT compiler version 4.8.1 ( Sun May 28 08:30:56 UTC 2017)
Which is the latest for freebsd, I get the following error:

Error: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
  at System.Net.WebConnection.Read (System.Net.HttpWebRequest request, System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x0002e] in <65d66c5eaa6a48038257422d3c294dab>:0
  at System.Net.WebSockets.ClientWebSocket+<ReceiveAsync>c__AnonStorey5.<>m__0 () [0x0017c] in <65d66c5eaa6a48038257422d3c294dab>:0
  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x00012] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
  at System.Threading.Tasks.Task.Execute () [0x00016] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <dbb16e0bacdc4a0f87478e401bc29b6c>:0
  at Coinbase+<WSfeedAsync>d__1.MoveNext () [0x001fd] in <5954f9a944254d6f8f184b8a9d4c72b8>:0

It appears I am not the only one that has tripped over this problem: https://stackoverflow.com/questions/12369881/c-sharp-websocket-mac-os-x

And for a work around, I told nginx on the freebsd server to act as a 'SSL'non-ssl proxy, that is turning the wss://secure-websocket in c# into a ws:// type, which does work. I am quite new to c# so is this a bug I should be reporting, is this the right place to report it? 

My apologies if it is not, 

-- Cheers
-- Paul
Comment 1 Paul 2017-07-08 00:35:16 UTC
I pasted the wrong link for 'others appear to have this problem', it should have been: https://stackoverflow.com/questions/40301543/xamarin-mono-clientwebsocket-implementation-doesnt-work-for-secure-sockets my apologies.
Comment 2 Paul 2017-07-13 05:49:11 UTC
After my WS:// workaround I run into yet another problem with System.Net.WebSockets I will not bore with the exact details, to make a short report (Will upload source code and binaries for all the different crashes so far later) System.Net.WebSockets should be classes as unusual as it stands with mono
Comment 3 Paul 2017-07-13 05:49:20 UTC
Comment 4 Marek Safar 2017-09-11 17:46:59 UTC
Could you share a repro we can try to diagnose the issue?
Comment 5 Paul 2017-09-11 18:22:01 UTC
Oh _expletive_ I utterly forgot about this one, I will have a BSD server I can spin up an example on over the next week, will post it public on gitlab
Comment 6 Paul 2017-09-11 19:52:20 UTC
This is not a perfect example! I just scribbled it together till I am at a better work station but the following linked code will compile in both windows, FreeBSD and linux but only work in windows.

Comment 7 Marek Safar 2017-09-12 09:24:39 UTC
I cannot reproduce the issue using attached example and Mono (2017-06/1afb931de69) (64-bit)
Comment 8 Paul 2017-09-12 11:46:13 UTC
Please wait for more extensive example though as the main base for this problem is freebsd, there is no mono 5 yet

Note You need to log in before you can comment on or make changes to this bug.