dotnet/runtime

SerialPort constantly throws IOException

Open

#113,296 opened on 2025年3月8日

GitHub で見る
 (14 comments) (3 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.IO.Portshelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

Description

The SerialPort seems to be broken in .NET 9. It throws this exception all the time: System.IO.IOException: "The I/O operation has been aborted because of either a thread exit or an application request."

This code has worked wonderfully in older versions of .NET but now it only fails. I can read and write from the serial port synchronously, i.e. wait for a response after sending a request. But for this project I need constant awareness on the port to always handle incoming data.

See attached demo code that reproduces the bug immediately. SerialPort is unusable like this. Run the project with the name of a serial port as only command line argument.

Reproduction Steps

Run attached code.

Expected behavior

Reading whatever bytes have been received.

Actual behavior

System.IO.IOException: "The I/O operation has been aborted because of either a thread exit or an application request."

Regression?

I think so.

Known Workarounds

None

Configuration

.NET 9 Windows 11 x64 Not tested anything else

Other information

The web suggests that something is tampering with the serial port. But that's not the case. I can verify with PuTTY that the serial port is working fine and receiving data. I can also send data over the port from .NET (ignoring these exceptions) and the data is properly received on the other end. I just can't receive any of the data that is sent, and I have these exceptions in a very tight loop.

SerialPortTest.zip

コントリビューターガイド