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.

E.g. “–KEEP_ALIVE_OPTION=1”.

This treats by the parser as no value: Option 'keep_alive_option" has no value. Required option ‘keep_alive_option’ is missing.

public class KeepAliveOptions
    {
        [Option(Required = true)]
        public string KEEP_ALIVE_OPTION { get; set; }
        [Option(Required = true)]
        public string LOGIN_URL { get; set; }
        [Option(Required = true)]
        public string ADVISOR_PASSWORD { get; set; }
        [Option(Required = true)]
        public string COMPANY_NUMBER { get; set; }
        [Option(Required = true)]
        public string OUT_DIR { get; set; }
        [Option(Required = true)]
        public string UserID { get; set; }
        [Option(Required = true)]
        public string Password { get; set; }
    }
public ParserResult<T> Parse<T>(string[] args) where T : IScriptOptions
        {
            Parser parser = new(s =>
            {
                s.CaseSensitive = false;
                s.IgnoreUnknownArguments = true;
                s.HelpWriter = Parser.Default.Settings.HelpWriter;
            });

            var scriptOptions = new List<string>();

            for (int i = 0; i < args.Length; i++)
            {
                string option = $"--{args[i].TrimStart('/')}";

                scriptOptions.Add(option);
            }

            return parser.ParseArguments<T>(scriptOptions);
        }
var result = Parse<KeepAliveOptions>(args)
                    .WithParsed(keepAliveOptions => options = keepAliveOptions)

Tried to change KEEP_ALIVE_OPTION type to int, it doesn’t change anything

Fiddle: https://dotnetfiddle.net/vbujQc

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
yevheniia-alikberovacommented, Dec 28, 2021

@elgonzo when I change LINE_NUMBER value from 1 KEEP_ALIVE_OPTION is also recognized This is for fiddle example

var args = new string[] {"/SCRIPT_NAME=DEALER_TRACK_KEEP_ALIVE", "/OEM_FAMILY=GM", "/COMPLAINT_CODE=\"0131\"", "/OUT_DIR=C:\\\\Applications\\\\DataFiles\\\\", "/KEEP_ALIVE_OPTION=1", "/STORY=\"Lorem ipsum #UPDATE#dolor sit amet\"", "/DEALER_TRACK_LOGIN_URL=https://blah", 
 "/DEALER_TRACK_UserID=myId", "/DEALER_TRACK_Password=myPwd12", "/DEALER_TRACK_ADVISOR_PASSWORD=\"asd\"", "/DEALER_TRACK_COMPANY_NUMBER=\"TT\"", "/RO_NUMBER=3464990", "/LINE_NUMBER=1", "/CAUSAL_PART_NUMBER=\"11546959:SL-N-BOLT (00293-CKT)\""};
1reaction
elgonzocommented, Dec 28, 2021

My apologies, i deleted my comment by accident. I cannot directly restore it, so i have to post it again. That unfortunately means, you get another email notification for basically the same comment of mine. Sorry about that 😃


Alright. The problem is not with the --KEEP_ALIVE_OPTION option itself. This is just an unfortunate aribtrary side effect happening after CommandlineParser went off the rails.

<strike>The actual cause of the problem are the many unknown options specified for the CLI invocation, and the actual bug is CommandlineParser not being able to cope with that many unknown options and completely losing its mind and going crazy. The particular order in which unknown and known options follow each other is probably also playing a role here, although i have not investigated in that direction any further…</strike> (EDIT: False conclusion, see my next comment below)

(By the way, in the concrete example you provided, it would just be enough to add the missing LINE_NUMBER option to DTLoginOptions class, and it kinda works: https://dotnetfiddle.net/P8O8dA Only “kinda” of course, because i think that this is just circumstantial behavior, and any other unknown option you add to the CLI invocation might make CommandlineParser lose its mind again 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why I cannot parse "+1" to int? [duplicate]
I am trying to parse +1 value to an int value. In my code +1 is a String and i am trying to...
Read more >
Black cannot parse multiple unpacking operations in one line
Describe the bug Black cannot parse an expression with multiple unpacking operations on one line that executes fine with Python.
Read more >
Android Question Exception: Cannot parse: -1 as boolean
I port a working code from VB to B4A. When data in Bluetooth communication, I received "Exception: Cannot parse: -1 as boolean" error...
Read more >
Re: cannot parse the file - SOLVED - Adobe Support Community
My party trick is to drag the recalcitrant file into a hex editor and look at the header because every format has its...
Read more >
How to resolve the error: "Message Cannot parse null string"
The error I am getting is: HTTP Status 500 – Internal Server Error Type Exception Report Message Cannot parse null string
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