HttpListener cannot be safely stopped and started by jonmdev
[Tool] Searching for HttpListener ObjectDisposedException, HttpListener cannot be restarted, HttpListener stop start exception, System.Net.HttpRequestQueueV2Handle ObjectDisposedException, HttpListener disposed object (IncludeOpen=True, IncludeClosed=True, IncludeIssues=True, IncludePullRequests=False, CreatedAfter=N/A)
[Tool] Found 37 issues, 20 comments, 37 returned results (11798 ms)
[Tool] Obtained 5 comments for issue #96705: C# HttpListener will show ObjectDisposedException if you stop listen after start listen immediately
[Tool] Obtained 6 comments for issue #30284: [HttpListener] HttpListener Start()/Stop()/Start()/BeginGetContext() causes ObjectDisposedException on Windows
If you need more details on any of these issues or further related discussions, let me know!
Triage for dotnet/runtime#116190.
Last updated: 2025-06-01_11-59-06
Here are related issues and discussions for issue #116190 ("HttpListener cannot be safely stopped and started"):
1. Issue #96705 (January 2024) - "C# HttpListener will show ObjectDisposedException if you stop listen after start listen immediately"
HttpListenerthrows anObjectDisposedException. The exception is seen in debug logs but is caught internally and does not affect the actual call toStop().HttpListeneris discouraged for new development and is unlikely to receive fixes for such issues.2. Issue #30284 (July 2019) - "[HttpListener] HttpListener Start()/Stop()/Start()/BeginGetContext() causes ObjectDisposedException on Windows"
Stop()and thenStart()on anHttpListener, followed byBeginGetContext(), results in anObjectDisposedExceptiondue to a disposedThreadPoolBoundHandle. The problem is specific to .NET Core (not .NET Framework).Stop()disposes an internal handle, butStart()does not recreate it, so subsequent operations fail.Stop()followed byStart()should be valid, but this is not the case in .NET Core.3. Issue #71364 (June 2022) - "HttpListenerResponse: Unhandled exception. System.ObjectDisposedException"
ObjectDisposedExceptionwhen usingHttpListener.GetContext()on Linux with large requests. The exception does not occur on Windows.HttpListeneris not in active development and would only accept community contributions for fixes.4. Issue #25947 (April 2018) - "Invalid HttpListener.Stop() behaviour"
HttpListener.Stop(), including errors on client connections and exceptions when closingClientWebSocket.5. Issue #35526 (April 2020) - "[HttpListener] No way to stop HttpListener from GetContext"
GetContext()from another thread, there is no way to stop the listener cleanly, leading to blocked threads.HttpListener.6. Issue #37242 (June 2020) - "[HttpListener] Failure in HttpListener.Start causes HttpListener get disposed automatically"
HttpListener.Start()throws, the instance is disposed and cannot be reused, which is not documented and can surprise users.Summary of Findings
HttpListenerlifecycle management, especially aroundStop()andStart()sequences.HttpListeneris not in active development, is discouraged for new projects, and fixes are unlikely unless contributed by the community.References:
If you need more details on any of these issues or further related discussions, let me know!