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.

2.4.0-beta.81 throws an ObjectDisposedException sometimes

See original GitHub issue

Describe the bug

I needed Ctrl-C support, so I was happy to find that the latest beta had just gotten that feature. But now I’m seeing an ObjectDisposedException - but only when running without a debugger. While debugging, I see nothing.

To Reproduce I’ve produced this program that exhibits the behavior.

using System;
using System.Threading;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Hosting;

namespace ConsoleApp1
{
    class Program
    {
        static async Task<int> Main(string[] args)
        {
            return await new HostBuilder()
                .RunCommandLineApplicationAsync<MyProgram>(args);
        }
    }

    class MyProgram
    {
        protected int OnExecute(CommandLineApplication app, CancellationToken cancellationToken)
        {
            Console.WriteLine("Entered. Waiting 10s");
            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(100);
                if (cancellationToken.IsCancellationRequested)
                {
                    Console.WriteLine("Cancelled");
                    break;
                }
            }

            Console.WriteLine("Finished");

            return 0;
        }
    }
}

Expected behavior Program terminates without exception.

Screenshots When cancelling image

When running till end image

Additional context

Stacktrace thrown.

Unhandled Exception: System.ObjectDisposedException: Safe handle has been closed
   at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at McMaster.Extensions.Hosting.CommandLine.Internal.CommandLineLifetime.<>c__DisplayClass11_0.<WaitForStartAsync>b__1(Object _, EventArgs __)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Allanncommented, Aug 17, 2019

Thanks, I ended up doing that and installed beta 99 and I no longer see the exception during shutdown.

1reaction
natemcmastercommented, Aug 13, 2019

Give 2.4.0-beta.94 a try and let me know if it doesn’t resolve your issue.

https://www.myget.org/feed/natemcmaster/package/nuget/McMaster.Extensions.CommandLineUtils/2.4.0-beta.94

Install-Package McMaster.Extensions.CommandLineUtils -Version 2.4.0-beta.94 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json
Read more comments on GitHub >

github_iconTop Results From Across the Web

ObjectDisposedException Class (System)
An ObjectDisposedException is thrown when you try to access a member of an object that implements the IDisposable interface or IAsyncDisposable interface, ...
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