sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Modified Hello world sample shows strange behavior

Open vivekmishra-sft opened this issue 10 years ago • 5 comments

Steps to reproduce

Follow the steps given at [https://www.microsoft.com/net/core#windows] and use the following modified version of Hello world program:

using System;
namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.Write("Enter a number to see magic: ");
            int num = Convert.ToInt32(Console.ReadLine());
            for(int i=0; i <=num; i++)
            {
               Console.WriteLine(i);
            }
        }
    }
}

Expected behavior

The program should roduce the following as ouptut(Let us suppose user enters 5): Hello World! Enter a number to see magic: 5 1 2 3 4 5

Actual behavior

The program gives the following as ouptut(Let us suppose user enters 5): Hello World! 5 Enter a number to see magic: 1 2 3 4 5

Environment data

dotnet --info output: .NET Command Line Tools (1.0.0-preview1-002702)

Product Information: Version: 1.0.0-preview1-002702 Commit Sha: 6cde21225e

Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-x64

vivekmishra-sft avatar May 23 '16 05:05 vivekmishra-sft

Hi, I don't see any problem with the above code.I have the same environment data as yours and when i run the above code, it works fine for me.No errors for me.The expected behaviour is what i got.Try restarting the VS and run again.

sravan1022 avatar May 23 '16 06:05 sravan1022

@sravan1022 I am using the "dotnet cli" to run the program. The issue above gives you the exact steps to follow, when you follow the provided link. I know that this runs in visual studio but when I run it using dotnet run command, it gives me the strange output as given above.

vivekmishra-sft avatar May 23 '16 06:05 vivekmishra-sft

It would be nice, if .NET Core would ensure that stdio is flushed, before reading the input. Might be a corefx problem?

fubar-coder avatar May 24 '16 06:05 fubar-coder

I believe @eerhardt fixed this recently.

davidfowl avatar May 24 '16 06:05 davidfowl

Yes, this issue was fixed with dotnet/cli#3013, but it didn't make it into "Preview1". It is only fixed in the latest "Preview2" nightly builds.

You can work around this issue for now by saying 'dotnet path-to-your-assembly.dll' instead of calling 'dotnet run'.

eerhardt avatar May 24 '16 12:05 eerhardt