Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help text generation throws InvalidOperationException on Mono #203

Closed
tooh opened this issue Jan 4, 2019 · 14 comments
Closed

Help text generation throws InvalidOperationException on Mono #203

tooh opened this issue Jan 4, 2019 · 14 comments
Assignees
Labels
Milestone

Comments

@tooh
Copy link

tooh commented Jan 4, 2019

Describe the bug
upgrade from 2.2.5 -> 2.3 breaks application

To Reproduce
Steps to reproduce the behavior:

  1. Using this version of the library '2.2.5.'
  2. Run this code '....'
  3. With these arguments '....'
  4. See error

Expected behavior
Upwards compatibility

Screenshots
Unhandled Exception:
System.InvalidOperationException: The Process object must have the UseShellExecute property set to false in order to redirect IO streams.
at System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) [0x00060] in <23340a11bb41423aa895298bf881ed68>:0
at System.Diagnostics.Process.Start () [0x00032] in <23340a11bb41423aa895298bf881ed68>:0
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
at McMaster.Extensions.CommandLineUtils.Pager.CreateWriter () [0x00064] in <5f42c33014224597b1fabe346c86217b>:0
at System.Lazy1[T].CreateValue () [0x00081] in <98fac219bd4e453693d76fda7bd96ab0>:0 at System.Lazy1[T].LazyInitValue () [0x00080] in <98fac219bd4e453693d76fda7bd96ab0>:0
at System.Lazy1[T].get_Value () [0x0003a] in <98fac219bd4e453693d76fda7bd96ab0>:0 at McMaster.Extensions.CommandLineUtils.Pager.get_Writer () [0x00013] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ShowHelp (System.Boolean usePager) [0x00041] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ShowHelp () [0x00000] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessOption () [0x00246] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessNext () [0x00033] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.Process () [0x00015] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse (System.String[] args) [0x00014] in <5f42c33014224597b1fabe346c86217b>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00000] in <5f42c33014224597b1fabe346c86217b>:0 at ClienteleCLI.Program.Main (System.String[] args) [0x00130] in <27420bcba69640678847b326b3cb6ebd>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: The Process object must have the UseShellExecute property set to false in order to redirect IO streams. at System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) [0x00060] in <23340a11bb41423aa895298bf881ed68>:0 at System.Diagnostics.Process.Start () [0x00032] in <23340a11bb41423aa895298bf881ed68>:0 at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start() at McMaster.Extensions.CommandLineUtils.Pager.CreateWriter () [0x00064] in <5f42c33014224597b1fabe346c86217b>:0 at System.Lazy1[T].CreateValue () [0x00081] in <98fac219bd4e453693d76fda7bd96ab0>:0
at System.Lazy1[T].LazyInitValue () [0x00080] in <98fac219bd4e453693d76fda7bd96ab0>:0 at System.Lazy1[T].get_Value () [0x0003a] in <98fac219bd4e453693d76fda7bd96ab0>:0
at McMaster.Extensions.CommandLineUtils.Pager.get_Writer () [0x00013] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ShowHelp (System.Boolean usePager) [0x00041] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ShowHelp () [0x00000] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessOption () [0x00246] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessNext () [0x00033] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.Process () [0x00015] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse (System.String[] args) [0x00014] in <5f42c33014224597b1fabe346c86217b>:0
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00000] in <5f42c33014224597b1fabe346c86217b>:0
at ClienteleCLI.Program.Main (System.String[] args) [0x00130] in <27420bcba69640678847b326b3cb6ebd>:0

Additional context
Macos

@natemcmaster
Copy link
Owner

Can you share code that reproduces this problem? I developed the Pager api on macos so I'm not sure what's wrong.

@natemcmaster natemcmaster added the more-info-needed Please provide more information. label Jan 4, 2019
@tooh
Copy link
Author

tooh commented Jan 4, 2019

I will prepare a code snippet. Probably tomorrow morning.

BTW you refer to pager, as i understand a new feature. My code is more than 6 months old. I’ m not aware I use this.

@no-response no-response bot removed the more-info-needed Please provide more information. label Jan 4, 2019
@natemcmaster
Copy link
Owner

It's new code in the library, not your code, that likely has a bug. I'm just trying to figure out if you're doing anything special to trigger this. It doesn't reproduce for me.

What is supposed to happen is that running dotnet MyApp.dll --help on macOS and Linux shows help text using the less pager.

@natemcmaster natemcmaster added bug more-info-needed Please provide more information. labels Jan 4, 2019
@tooh
Copy link
Author

tooh commented Jan 5, 2019

Below a snippet of the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Net;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using McMaster.Extensions.CommandLineUtils.Validation;
using McMaster.Extensions.CommandLineUtils.Abstractions;
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using Clientele.Application.Common;
using Clientele.Proxies.SupportCall.SupportCallWS;
using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace CLI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        // [STAThread]
        static int Main(string[] args)
        {
            ArgumentEscaper.EscapeAndConcatenate(args);
           
           var app = new CommandLineApplication();

            app.HelpOption("-?|-h|--help");
            app.FullName = "CLI";
            app.Name = "CLI";
            app.Description = "Clientele CLI to create supportcalls";

            app.VersionOptionFromAssemblyAttributes(typeof(Program).Assembly);
            // app.VersionOption("--version", "1.0.0");
            var optionSummary = app.Option("-s|--summary <SUMMARY>", "The summary", CommandOptionType
                                   .SingleValue)
                                   .IsRequired();
            var optionNotes = app.Option("-n|--notes <NOTES>", "Notes", CommandOptionType
                                   .SingleValue);
            var optionCallType = app.Option("-t|--type <TYPE>", "Support call type I , R, S or P", CommandOptionType
                                    .SingleValue)
                                    .IsRequired()
                                    .Accepts(v => v.Values("I", "R", "S", "P"));

            app.OnExecute(() =>
            {

                var summary = "";
                summary = optionSummary.Value();

                var notes = optionNotes.HasValue()
                    ? optionNotes.Value()
                    : "";

                var type = "";
                   
                return 0;
            });

            
            return app.Execute(args);
        }
    }
}

@no-response no-response bot removed the more-info-needed Please provide more information. label Jan 5, 2019
@natemcmaster
Copy link
Owner

I've run your code sample on macOS and can't reproduce on .NET Core 2.2. Which version of .NET are you running? How are you invoking your app? Which terminal application or IDE? When I do dotnet run -- --help, everything seems to work just fine.

image

@tooh
Copy link
Author

tooh commented Jan 5, 2019

dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.302
Commit: 9048955601

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /usr/local/share/dotnet/sdk/2.1.302/

Host (useful for support):
Version: 2.1.2
Commit: 811c3ce6c0

.NET Core SDKs installed:
2.0.3 [/usr/local/share/dotnet/sdk]
2.1.4 [/usr/local/share/dotnet/sdk]
2.1.301 [/usr/local/share/dotnet/sdk]
2.1.302 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

@tooh
Copy link
Author

tooh commented Jan 5, 2019

And now I'm puzzled

When I run my app as follows

mono64 '~/projects/clienteleCLI/bin/debug/ClienteleCLI.exe'

it runs ok.

I'm not really into .NET but when I follow your suggestion to run as

dotnet run 

the following happens

dotnet run 
/Users/peter/Projects/ClienteleCLI/ClienteleCLI.csproj : error NU1202: Package dotnet-mono 0.5.4 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package dotnet-mono 0.5.4 supports:
/Users/peter/Projects/ClienteleCLI/ClienteleCLI.csproj : error NU1202:   - netcoreapp2.0 (.NETCoreApp,Version=v2.0)
/Users/peter/Projects/ClienteleCLI/ClienteleCLI.csproj : error NU1202:   - netcoreapp2.1 (.NETCoreApp,Version=v2.1)

The build failed. Please fix the build errors and run again.

@natemcmaster
Copy link
Owner

How are you invoking your app? Which terminal application or IDE? VS for Mac? Rider? Also, can you share the ClienteleCLI.csproj file? I'm confused about whether you are trying to use .NET Core or Mono.

@natemcmaster
Copy link
Owner

I was able to reproduce the problem on Mono. Give this updated version of the package a try: https://www.myget.org/feed/natemcmaster/package/nuget/McMaster.Extensions.CommandLineUtils/2.3.1-build.475

@natemcmaster natemcmaster added this to the 2.3.1 milestone Jan 5, 2019
@natemcmaster natemcmaster self-assigned this Jan 5, 2019
@tooh
Copy link
Author

tooh commented Jan 5, 2019

I can not update from the VS IDE because this update is not available yet,

Is this the proper way to install this update ?

nuget install McMaster.Extensions.Hosting.CommandLine -Version 2.3.1-build.475 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json 
Feeds used:
  /Users/peter/.nuget/packages/
  https://www.myget.org/F/natemcmaster/api/v3/index.json



Attempting to gather dependency information for package 'McMaster.Extensions.Hosting.CommandLine.2.3.1-build.475' with respect to project '/Users/peter/Projects/ClienteleCLI', targeting 'Any,Version=v0.0'
Gathering dependency information took 3.46 sec
Attempting to resolve dependencies for package 'McMaster.Extensions.Hosting.CommandLine.2.3.1-build.475' with DependencyBehavior 'Lowest'
Unable to resolve dependency 'Microsoft.Extensions.Hosting'. Source(s) used: 'nuget.org'.

@tooh
Copy link
Author

tooh commented Jan 5, 2019

How are you invoking your app?
mone cli.exe

Which terminal application or IDE?
stand macOS terminal
VS for Mac?
VS 2017 form Mac
Also, can you share the ClienteleCLI.csproj file?

ClienteleCLI.csproj.zip

@natemcmaster
Copy link
Owner

dotnet add package McMaster.Extensions.CommandLineUtils --version 2.3.1-build.475 --source https://www.myget.org/F/natemcmaster/api/v3/index.json

@Jay-Jay-D
Copy link

Hey Nate,
First of all, thank you very much for maintaining this library!

I'm having the System.InvalidOperationException issue in using the version 2.3.1-build.475 in Mono 5.14.0.177

@natemcmaster
Copy link
Owner

@Jay-Jay-D can you open a new issue and describe steps to reproduce the problem?

@natemcmaster natemcmaster changed the title upgrade from 2.2.5 -> 2.3 breaks application Help text generation throws InvalidOperationException on Mono Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants