dotnet/runtime

SerialPort constantly throws IOException

Open

#113,296 建立於 2025年3月8日

在 GitHub 查看
 (14 留言) (3 反應) (0 負責人)C# (5,445 fork)batch import
area-System.IO.Portshelp wanted

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

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

貢獻者指南