Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 166891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:10:41+00:00 2026-05-11T12:10:41+00:00

I have what seems to be a simple problem that I can’t solve myself.

  • 0

I have what seems to be a simple problem that I can’t solve myself. I have a WinForm app, with main method modified to accept command line arguments like this:

    [STAThread]     static void Main(String[] args)     {         int argCount = args.Length;     } 

This code works fine and argCount is equals to 2 when compiled in debug mode with the following execution line: program.exe -file test.txt. However as soon as I compile the program in release mode, argCount is now 1 with the same command line arguments. The only argument contains ‘-file test.txt’. More than that it only happens if I run the compiled executable from obj/Release folder, but not from bin/Release. Unfortunately setup project takes executables from obj/Release so I can’t change that. Is this a known issue and is there a way around this problem?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:10:42+00:00Added an answer on May 11, 2026 at 12:10 pm

    The command line processing should be the same, therefore something else is going on. When I try this:

    class Program {     [STAThread]     static void Main(String[] args) {         Console.WriteLine('Have {0} arguments', args.Length);         for (int i = 0; i < args.Length; ++i) {             Console.WriteLine('{0}: {1}', i, args[i]);         }     } } 

    and then it from the various locations I get 100% consistent results, the only way of getting arguments ‘merged’ is to enclose them in quotes on the command line (which is specifically there to allow you do have arguments containing a space, see the last example below):

     PS C:\...\bin\Debug> .\ConsoleApplication1.exe one two three Have 3 arguments 0: one 1: two 2: three PS C:\...\bin\Debug> pushd ..\release PS C:\...\bin\Release> .\ConsoleApplication1.exe one two three Have 3 arguments 0: one 1: two 2: three PS C:\...\bin\Release> pushd ..\..\obj\debug PS C:\...\obj\Debug> .\ConsoleApplication1.exe one two three Have 3 arguments 0: one 1: two 2: three PS C:\...\obj\Debug> pushd ..\release PS C:\...\obj\Release> .\ConsoleApplication1.exe one two three Have 3 arguments 0: one 1: two 2: three PS C:\...\obj\Release> .\ConsoleApplication1.exe -file test.txt Have 2 arguments 0: -file 1: test.txt PS C:\...\obj\Release> .\ConsoleApplication1.exe '-file test.txt' Have 1 arguments 0: -file test.txt 

    Additional While launching from a command prompt makes it easy to see what is being passed it can be hard to check when another application launches yours. However tools like Process Explorer will show the command line used to start a program (double click on a process and look at the image tab).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.