question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.ObjectDisposedException on WatsonTCPClient.Connect()

See original GitHub issue

Hi,

I’m think I found a bug on the WatsonTCPClient. Right now I’m using the WatsonTcpClient like this: I do not keep a connection alive, I connect only when I send some data from the client then disconnect. If I send data multiple times in a row like this I get the following error:

System.ObjectDisposedException: "Safe handle has been closed. ObjectDisposed_ObjectName_Name"

Debug Log: [WatsonTcpClient] connecting to 127.0.0.1:25000 [WatsonTcpClient] exception encountered: { "ClassName": "System.ObjectDisposedException", "Message": "Safe handle has been closed.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)\r\n at System.Threading.WaitHandle.WaitOneNoCheck(Int32 millisecondsTimeout)\r\n at System.Threading.WaitHandle.WaitOne(TimeSpan timeout, Boolean exitContext)\r\n at WatsonTcp.WatsonTcpClient.Connect()", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2146232798, "Source": "System.Private.CoreLib", "WatsonBuckets": null, "ObjectName": "SafeHandle" }

Code to reproduce this error: ` // See https://aka.ms/new-console-template for more information

using WatsonTcp;

var s = new WatsonTcpServer(null, 25000); s.Events.MessageReceived += (sender, received_args) => { global::System.Console.WriteLine(“Message Received”); }; s.Callbacks.SyncRequestReceived = (request) => { global::System.Console.WriteLine(“SyncRequestReceived”); return new SyncResponse(request, DateTime.Now.ToString()); };

s.Start();

while (true) { var c = new WatsonTcpClient(“127.0.0.1”, 25000); c.Events.MessageReceived += (s, received_args) => { global::System.Console.WriteLine(“Message received”); }; c.Settings.DebugMessages = true; c.Settings.Logger += (s, m) => { global::System.Console.WriteLine(m); }; c.Connect(); var response = c.SendAndWait(5000, new byte[] { 1, 2, 3 }); Console.ReadLine(); } `

I’m using .Net 6 and the latest WastonTcp version via NuGet 4.8.14.6

Regards

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jchristncommented, Jan 7, 2022

@ahubertus44 dude - thank you. Very generous, I really appreciate it!

1reaction
jchristncommented, Jan 7, 2022

Wow, thank you @ahubertus44! My receive address is: 32UAbVDvqRuwsJ4zq8tsamWgjFC9fp8sp8 Much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.ObjectDisposedException in TCP sockets in C# - ...
When I run my server and the client first everything works and a "client connected" message appears. The problem is when I am...
Read more >
ObjectDisposedException Class (System)
Determines whether the specified object is equal to the current object. (Inherited from Object). GetBaseException(). When overridden in a derived class, returns ...
Read more >
System.ObjectDisposedException: Cannot access a ...
Dispose runs socket.Client.Close(); . Thread t is now aborting and enters the finally block. Tries to run socket.Close(); . Gets exception ...
Read more >
Cannot access a disposed object. Object name: 'System. ...
I have client/server program. I get this exception in the server. Cannot access a disposed object. Object name: 'System.Net.Sockets.
Read more >
C# acces vars & controls from static field not working
I get the error: 'Error CS0236 A field initializer cannot reference the non-static field, method, or property 'ClientMenu.MessageReceived(byte[]) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found