dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.2k stars 4.72k forks source link

Console.WriteLine no longer outputs to the screen on Ubuntu 20.04 after upgrading to .NET version 6.0 #61468

Open DavidPesta opened 2 years ago

DavidPesta commented 2 years ago

Problem encountered on https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/run Operating System: linux

I am inside of the MyApp directory. Upon typing "dotnet run" and pressing the enter key, a brief pause responds with the command prompt without displaying "Hello, World!"

Operating system is Ubuntu 20.04 LTS (Focal Fossa)

I noticed this problem with my other console programs after I upgraded their TargetFramework to net6.0. So I followed the tutorial exactly and got the same (empty) result.

mairaw commented 2 years ago

@dagood @leecow can you help with this issue on Ubuntu?

dagood commented 2 years ago

It works for me on 20.04. Some more info that comes to mind that could help diagnose:

Transferring to dotnet/runtime for more insight and maybe more specific things to check. /cc @dleeapho

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-system-console See info in area-owners.md if you want to be subscribed.

Issue Details
Problem encountered on https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/run Operating System: linux I am inside of the MyApp directory. Upon typing "dotnet run" and pressing the enter key, a brief pause responds with the command prompt without displaying "Hello, World!" Operating system is Ubuntu 20.04 LTS (Focal Fossa) I noticed this problem with my other console programs after I upgraded their TargetFramework to net6.0. So I followed the tutorial exactly and got the same (empty) result.
Author: DavidPesta
Assignees: -
Labels: `area-System.Console`, `untriaged`
Milestone: -
DavidPesta commented 2 years ago

dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff

Runtime Environment: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: ubuntu.20.04-x64 Base Path: /snap/dotnet-sdk/150/sdk/6.0.100/

Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa

.NET SDKs installed: 6.0.100 [/snap/dotnet-sdk/150/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.0 [/snap/dotnet-sdk/150/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.0 [/snap/dotnet-sdk/150/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

Changing TargetFramework to net5.0 in one of the old projects breaks it in other ways. An error that didn't happen when dotnet 5 was installed:

Predefined type 'System.Object' is not defined or imported [IntroLibrary]csharp(CS0518)
'object' does not contain a constructor that takes 0 arguments [IntroLibrary]csharp(CS1729)
class IntroLibrary.Person

and

Unnecessary using directive. [IntroLibrary]csharp(CS8019)
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [IntroLibrary]csharp(CS0246)

Perhaps there is no trace of .NET 5 on my system after the Ubuntu snap upgraded itself. (I speculate.)

Going back to the tutorial app, running dotnet on the MyApp.dll directly works:

$ dotnet bin/Debug/net6.0/MyApp.dll
Hello, World!
leecow commented 2 years ago

We are seeing some instances of this with dot net run but, as you discovered, dotnet bin/Debug/net6.0/MyApp.dll works fine. Also, if you're using VS Code, running the app or debugging is outputting correctly.

dagood commented 2 years ago

Ubuntu snap

Ah, for the record, my attempt was installing via apt. I don't have an environment set up that works with snaps to try that out. (I don't know if this is related, but wanted to clarify for others who might look into this. 😄)

dleeapho commented 2 years ago

cc @NikolaMilosavljevic

CarlSargunar commented 2 years ago

Seen this too myself on Ubuntu 18.4 LTS

vgb1993 commented 2 years ago

I might be having the same problem. First we thought it was the Linux distribution, CPU, etc... But the problem keeps poping up. In out case the thing is extra weird: It works sometimes only.

The application is a long running process, the code calls Console.WriteLine for every message recived from Signlr. The call is handled correctly and the rest of the code runs as expected. But the Console.WriteLine message can not be seen. Oddly enough some other messages can be seen.

It literaly is the first instruction after reciving a message via Signalr:

        Connection.On<string, ChannelMessage>( "InputMessage", ( channelId, message ) =>
        {
            Console.WriteLine( $"Message recived : {message.GetType().Name} in thread { Thread.CurrentThread.ManagedThreadId }" );
            this.OnInputMessage( channelId, message );
        } );

Some times it gets printed, some times it doesen't. The rest of the code runs as expected an returns a response.

We are using: Ubuntu 18 as well

<Project Sdk="Microsoft.NET.Sdk.Worker">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <SignAssembly>false</SignAssembly>
    <NoWin32Manifest>true</NoWin32Manifest>
    <StartupObject></StartupObject>
    <nullable>enable</nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

Any ideas?

adamsitnik commented 2 years ago

@tmds is there any chance you could take a look at this?

vgb1993 commented 2 years ago

I’d like to update my case.

Aparently we have solved our issue. And we don’t think it was related to the Linux distribution.

We succesfully manage to get a consistent behaviour after tweaking SignalR: sending our own ping message from both sides periodically.

Also, we changed our SerialPort listener to use Observables instead of Events. We where doing some async stuff inside of our listener and with the event listener some resources where getting disposed before the async code could get executed.

Anyway. We no longer have this issue.

Cheers