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

Pass command line empty string arguments to C# console application. #1062

Open
powerumc opened this issue Jun 24, 2019 · 3 comments
Open

Pass command line empty string arguments to C# console application. #1062

powerumc opened this issue Jun 24, 2019 · 3 comments

Comments

@powerumc
Copy link

I wrote simple console application.

using System;

namespace commandline_test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($"CommandLine={Environment.CommandLine}");

            foreach(var arg in args) {
                Console.WriteLine($"'arg={arg}'");
            }
        }
    }
}

I need to pass empty string arguments to C# console application.
But some shell, some framework can not.
Why difference is it?

The test results

  • .Net Framework depends on shell.

  • .Net core is ignore empty string alway.

  • PowerShell is ignore empty string alway.

  • Mono is only bash.

  • Windows

    • PowerShell
      • (.net framework) a.exe --a "" --b ""
        • arg='--a'
        • arg='--b'
      • (.net framework) a.exe --a """" --b """"
        • arg='--a'
        • arg=' --b '
      • (mono) mono a.exe --a "" --b ""
        • arg='--a'
        • arg='--b'
      • (.net core) dotnet run --a "" --b ""
        • 'arg='--a'
        • arg='--b'
    • Cmd
      • (.net framework) a.exe --a "" --b ""
        • arg='--a'
        • arg=''
        • arg='--b'
        • arg=''
      • (mono) mono a.exe --a "" --b ""
        • arg='--a'
        • arg=''
        • arg='--b'
        • arg=''
      • (.net core) dotnet run --a "" --b ""
        • arg='--a'
        • arg='--b'
  • Mac

    • bash
      • (mono) mono a.exe --a "" --b ""
        • arg='--a'
        • arg=''
        • arg='--b'
        • arg=''
      • (.net core) dotnet run --a "" --b ""
        • arg='--a'
        • arg='--b'
      • (bash script) ./a.sh --a "" --b ""
        • arg='--a'
        • arg=''
        • arg='--b'
        • arg=''
    • pwsh
      • (mono) mono a.exe --a "" --b ""
        • arg='--a’
        • arg='--b'
      • (.net core) dotnet run --a "" --b ""
        • arg='--a'
        • arg='--b'
  • Linux

    • bash
      • (mono) mono a.exe --a "" --b ""
        • arg='--a'
        • arg=''
        • arg='--b'
        • arg=''
      • (.net core) dotnet run --a "" --b ""
        • arg='--a'
        • arg='--b'
      • (bash script) ./a.sh --a "" --b ""
        • arg='--a'
        • arg=''
        • arg='--b'
        • arg=''
@ghost
Copy link

ghost commented Jun 24, 2019

Interesting! What version(s) of Framework/Core/Mono have you tried this in? Curious that this has not broken a lot of applications out there that parse their commandlines.

@powerumc
Copy link
Author

@sujayvsarma
I did compiled the version.

  • .NET Framework: 4.7.2 (msbuild: 16.0.40.50150)
  • .NET Core: 2.2 (2.2.105)
  • Mono: Mono JIT compiler version 5.16.0

@powerumc
Copy link
Author

Is this a bug, or is there a plan to improve it?

333fred added a commit to dotnet/roslyn-analyzers that referenced this issue Sep 26, 2024
* Add an analyzer for Debug.Assert

As @jaredpar found in dotnet/roslyn#75163, interpolated strings in `Debug.Assert` can consume a surprising amount of memory. On modern .NET, this is fine; `Debug.Assert` has an interpolated string handler that will avoid the allocations if the assert isn't triggered. However, on our framework tests, this can be very bad and OOM our tests. So, this analyzer looks for cases where interpolated strings are passed to `Debug.Assert`, and recommends moving over to `RoslynDebug.Assert` instead, which is an interpolated string handler on all platforms. Note that I only did C# support, as there's no equivalent handler API for VB.

* Make sure RoslynDebug is available in one test.

* Trailing whitespace

* Run pack.

* Remove VB

* Pack again

* Use batch fixall provider

* Avoid passing empty string as command line argument

See microsoft/dotnet#1062

* Don't warn for constant strings.

* Apply suggestions from code review

Co-authored-by: Jared Parsons <[email protected]>

---------

Co-authored-by: Sam Harwell <[email protected]>
Co-authored-by: Jared Parsons <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant