Skip to content

.NET 6 regression on writing to character device #59754

Closed
@am11

Description

@am11

Create a console app with following content in Program.cs:

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

string path = "/dev/tty";
if (!File.Exists(path))
{
    throw new Exception(path + " is not available in this environment.");
}

var contentBytes = new byte[] { 1, 2, 3 };

using (var cts = new CancellationTokenSource())
{
    Task writingTask = File.WriteAllBytesAsync(path, contentBytes, cts.Token);
    cts.CancelAfter(TimeSpan.FromMilliseconds(500));

    await writingTask;
}

Console.WriteLine("Passed!");

On macOS (x64), run with .NET 5 (5.0.400), it prints Passed!. In .NET 6 (6.0.100-rtm.21479.10) it throws:

Unhandled exception. System.IO.IOException: Device not configured : '/dev/tty'
   at System.IO.RandomAccess.WriteAtOffset(SafeFileHandle handle, ReadOnlySpan`1 buffer, Int64 fileOffset)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.ThreadPoolValueTaskSource.ExecuteInternal()
--- End of stack trace from previous location ---
   at Microsoft.Win32.SafeHandles.SafeFileHandle.ThreadPoolValueTaskSource.GetResult(Int16 token)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.ThreadPoolValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.IO.File.<WriteAllBytesAsync>g__Core|72_0(String path, Byte[] bytes, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in /Users/adeel/projects/testdevtty/Program.cs:line 21
   at Program.<Main>(String[] args)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions