Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Cannot access a disposed object error when stopping NancyHost #2979

Open
1 task done
ghost opened this issue Sep 9, 2019 · 0 comments
Open
1 task done

Cannot access a disposed object error when stopping NancyHost #2979

ghost opened this issue Sep 9, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Sep 9, 2019

Description

I'm using NancyHost for self hosting. But whenever I try to Stop or Dispose the host, I get these two exceptions:

mscorlib: Cannot access a disposed object.
Object name: 'listener'.
  at System.Net.ListenerAsyncResult.GetContext () [0x0001c] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Net.HttpListener.EndGetContext (System.IAsyncResult asyncResult) [0x00099] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
--- End of stack trace from previous location where exception was thrown ---

  at Nancy.Hosting.Self.NancyHost+<>c__DisplayClass14_0.<Start>b__1 (System.Threading.Tasks.Task`1[TResult] contextTask) [0x00087] in <5e6fd4328ff54d50a87c10c9ee6cd54a>:0
mscorlib: Cannot access a disposed object.
Object name: 'listener'.
  at System.Net.ListenerAsyncResult.GetContext () [0x0001c] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Net.HttpListener.EndGetContext (System.IAsyncResult asyncResult) [0x00099] in <748af814b14a45f7803e4fe5c9300d51>:0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <52405d1838e24bc5b300f5ebeee9f7c4>:0 
--- End of stack trace from previous location where exception was thrown ---

  at Nancy.Hosting.Self.NancyHost+<>c__DisplayClass14_0.<Start>b__1 (System.Threading.Tasks.Task`1[TResult] contextTask) [0x00087] in <5e6fd4328ff54d50a87c10c9ee6cd54a>:0

Steps to Reproduce

The host function does this:

Task.Run(() =>
        {
            _host = new NancyHost(new HostConfiguration
            {
                UnhandledExceptionCallback = ExceptionHandler
            }, new Uri($"http://localhost:{port}"), new Uri($"http://127.0.0.1:{port}"));
            _host.Start();
            EmitSignal(nameof(OnStart)); // to notify the rest of code
        });

System Configuration

  • Nancy version: v2.0.0
  • Nancy host
    • Nancy.Hosting.Self
  • Environment (Operating system, version and so on): Windows 10 x64
  • .NET Framework version: .NetFramework 4.5.2 mono
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants