Standard input erratic if command line arguments present when debugging in VS2017












0















I have a weird problem where standard input behaves unexpectedly while debugging in Visual Studio 2017, but only if command line arguments are present. The problem does not occur in VS2010.



As a sample, consider a Windows Application targeting .Net 3.5 with this simple code:



static class Program
{
static void Main()
{
if (Console.In == null)
{
Console.WriteLine("Console.In: null");
}
else if (Console.In == StreamReader.Null)
{
Console.WriteLine("Console.In: " + Console.In.GetType().FullName);
}
else
{
Console.WriteLine("Console.In: " + Console.In.GetType().FullName);

string cmd;
while ((cmd = Console.In.ReadLine()) != null )
{
Thread.Sleep(1000);
}
}
}
}


When debugging this in VS2010, the debug output will be "Console.In: System.IO.StreamReader+NullStreamReader" regardless of if any (dummy) command line arguments are given in the start options for the project.



When debugging the exact same code in VS2017, if there are no command line arguments given, then standard input will still be the null stream. However, if command line arguments ARE given, the output will instead be "Console.In: System.IO.TextReader+SyncTextReader", and then it will proceed to crash on ReadLine() because it's actually incapable of reading from this stream:




Exception thrown: 'System.IO.IOException' in mscorlib.dll
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Not enough storage is available to process this command.




Why does VS2017 during debugging with command line arguments present generate this unexpected standard input reader? Can I get rid of it?



Alternatively, what would be a better way to do this? (What I'm trying to do is check if there is a useful standard input because if there is the real program can read some commands from it. If there is no standard input present it should just be ignored and the rest of the program proceed in a default code path.)



Environment: Windows 7 64bit, VS2017 15.9.2. I've checked this under both .Net 3.5 and 4.0 with the same results. (.Net 4.7.2 is installed on the machine).



Update 2018-11-22



The problem occurs on my machine and also for a colleague, both on Windows 7 64-bit.



Two other colleagues run Windows 10 and for them the problem does not occur. If on Windows 10, Console.In will, as expected, be a NullStreamReader even if command line arguments are present while debugging.










share|improve this question





























    0















    I have a weird problem where standard input behaves unexpectedly while debugging in Visual Studio 2017, but only if command line arguments are present. The problem does not occur in VS2010.



    As a sample, consider a Windows Application targeting .Net 3.5 with this simple code:



    static class Program
    {
    static void Main()
    {
    if (Console.In == null)
    {
    Console.WriteLine("Console.In: null");
    }
    else if (Console.In == StreamReader.Null)
    {
    Console.WriteLine("Console.In: " + Console.In.GetType().FullName);
    }
    else
    {
    Console.WriteLine("Console.In: " + Console.In.GetType().FullName);

    string cmd;
    while ((cmd = Console.In.ReadLine()) != null )
    {
    Thread.Sleep(1000);
    }
    }
    }
    }


    When debugging this in VS2010, the debug output will be "Console.In: System.IO.StreamReader+NullStreamReader" regardless of if any (dummy) command line arguments are given in the start options for the project.



    When debugging the exact same code in VS2017, if there are no command line arguments given, then standard input will still be the null stream. However, if command line arguments ARE given, the output will instead be "Console.In: System.IO.TextReader+SyncTextReader", and then it will proceed to crash on ReadLine() because it's actually incapable of reading from this stream:




    Exception thrown: 'System.IO.IOException' in mscorlib.dll
    An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
    Not enough storage is available to process this command.




    Why does VS2017 during debugging with command line arguments present generate this unexpected standard input reader? Can I get rid of it?



    Alternatively, what would be a better way to do this? (What I'm trying to do is check if there is a useful standard input because if there is the real program can read some commands from it. If there is no standard input present it should just be ignored and the rest of the program proceed in a default code path.)



    Environment: Windows 7 64bit, VS2017 15.9.2. I've checked this under both .Net 3.5 and 4.0 with the same results. (.Net 4.7.2 is installed on the machine).



    Update 2018-11-22



    The problem occurs on my machine and also for a colleague, both on Windows 7 64-bit.



    Two other colleagues run Windows 10 and for them the problem does not occur. If on Windows 10, Console.In will, as expected, be a NullStreamReader even if command line arguments are present while debugging.










    share|improve this question



























      0












      0








      0








      I have a weird problem where standard input behaves unexpectedly while debugging in Visual Studio 2017, but only if command line arguments are present. The problem does not occur in VS2010.



      As a sample, consider a Windows Application targeting .Net 3.5 with this simple code:



      static class Program
      {
      static void Main()
      {
      if (Console.In == null)
      {
      Console.WriteLine("Console.In: null");
      }
      else if (Console.In == StreamReader.Null)
      {
      Console.WriteLine("Console.In: " + Console.In.GetType().FullName);
      }
      else
      {
      Console.WriteLine("Console.In: " + Console.In.GetType().FullName);

      string cmd;
      while ((cmd = Console.In.ReadLine()) != null )
      {
      Thread.Sleep(1000);
      }
      }
      }
      }


      When debugging this in VS2010, the debug output will be "Console.In: System.IO.StreamReader+NullStreamReader" regardless of if any (dummy) command line arguments are given in the start options for the project.



      When debugging the exact same code in VS2017, if there are no command line arguments given, then standard input will still be the null stream. However, if command line arguments ARE given, the output will instead be "Console.In: System.IO.TextReader+SyncTextReader", and then it will proceed to crash on ReadLine() because it's actually incapable of reading from this stream:




      Exception thrown: 'System.IO.IOException' in mscorlib.dll
      An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
      Not enough storage is available to process this command.




      Why does VS2017 during debugging with command line arguments present generate this unexpected standard input reader? Can I get rid of it?



      Alternatively, what would be a better way to do this? (What I'm trying to do is check if there is a useful standard input because if there is the real program can read some commands from it. If there is no standard input present it should just be ignored and the rest of the program proceed in a default code path.)



      Environment: Windows 7 64bit, VS2017 15.9.2. I've checked this under both .Net 3.5 and 4.0 with the same results. (.Net 4.7.2 is installed on the machine).



      Update 2018-11-22



      The problem occurs on my machine and also for a colleague, both on Windows 7 64-bit.



      Two other colleagues run Windows 10 and for them the problem does not occur. If on Windows 10, Console.In will, as expected, be a NullStreamReader even if command line arguments are present while debugging.










      share|improve this question
















      I have a weird problem where standard input behaves unexpectedly while debugging in Visual Studio 2017, but only if command line arguments are present. The problem does not occur in VS2010.



      As a sample, consider a Windows Application targeting .Net 3.5 with this simple code:



      static class Program
      {
      static void Main()
      {
      if (Console.In == null)
      {
      Console.WriteLine("Console.In: null");
      }
      else if (Console.In == StreamReader.Null)
      {
      Console.WriteLine("Console.In: " + Console.In.GetType().FullName);
      }
      else
      {
      Console.WriteLine("Console.In: " + Console.In.GetType().FullName);

      string cmd;
      while ((cmd = Console.In.ReadLine()) != null )
      {
      Thread.Sleep(1000);
      }
      }
      }
      }


      When debugging this in VS2010, the debug output will be "Console.In: System.IO.StreamReader+NullStreamReader" regardless of if any (dummy) command line arguments are given in the start options for the project.



      When debugging the exact same code in VS2017, if there are no command line arguments given, then standard input will still be the null stream. However, if command line arguments ARE given, the output will instead be "Console.In: System.IO.TextReader+SyncTextReader", and then it will proceed to crash on ReadLine() because it's actually incapable of reading from this stream:




      Exception thrown: 'System.IO.IOException' in mscorlib.dll
      An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
      Not enough storage is available to process this command.




      Why does VS2017 during debugging with command line arguments present generate this unexpected standard input reader? Can I get rid of it?



      Alternatively, what would be a better way to do this? (What I'm trying to do is check if there is a useful standard input because if there is the real program can read some commands from it. If there is no standard input present it should just be ignored and the rest of the program proceed in a default code path.)



      Environment: Windows 7 64bit, VS2017 15.9.2. I've checked this under both .Net 3.5 and 4.0 with the same results. (.Net 4.7.2 is installed on the machine).



      Update 2018-11-22



      The problem occurs on my machine and also for a colleague, both on Windows 7 64-bit.



      Two other colleagues run Windows 10 and for them the problem does not occur. If on Windows 10, Console.In will, as expected, be a NullStreamReader even if command line arguments are present while debugging.







      .net visual-studio visual-studio-2010 visual-studio-2017 stdin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 13:50







      Oskar Berggren

















      asked Nov 21 '18 at 18:46









      Oskar BerggrenOskar Berggren

      5,10311031




      5,10311031
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418698%2fstandard-input-erratic-if-command-line-arguments-present-when-debugging-in-vs201%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418698%2fstandard-input-erratic-if-command-line-arguments-present-when-debugging-in-vs201%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen