ReadAsync blocks for .NET Core
See original GitHub issueHi,
this is a follow up issue to #114 and to the PR #115.
First of all, thanks for integrating the PR #115 and providing a new NuGet version.
Today, we tried to upgrade the SerialPortsStream library to the new version 2.3.0 in our project and found out that we still have issues with .NET Core 3.1 and using the ReadAsync
and WriteAsync
methods.
We could reproduce the issue with a pretty straight-forward unit test: We set up writing to the stream on COM1 and reading from COM2 (COM1 and COM2 are connected). For the .NET Core 3.1, the ReadAsync
blocks and never reads the bytes from the stream whereas for .NET 4.7.2 everything works as expected.
public async Task WriteAsync()
{
using (var serialPortStreamWrite = new SerialPortStream("COM1", 9600, 8, Parity.None, StopBits.One))
using (var serialPortStreamRead = new SerialPortStream("COM2", 9600, 8, Parity.None, StopBits.One))
{
serialPortStreamWrite.Open();
serialPortStreamRead.Open();
var buffer = new byte[1024];
var readTask = Task.Run(async () => await serialPortStreamRead.ReadAsync(buffer, 0, buffer.Length));
var bytes = new byte[] { 0x01, 0x02, 0x03 };
await serialPortStreamWrite.WriteAsync(bytes, 0, bytes.Length);
await serialPortStreamWrite.FlushAsync();
// ReadAsync blocks here even if something gets written and flushed to the underlying COM device.
// Fails for netcoreapp3.1, works with net472
await readTask;
Assert.That(buffer[0], Is.EqualTo(0x01));
Assert.That(buffer[1], Is.EqualTo(0x02));
Assert.That(buffer[2], Is.EqualTo(0x03));
}
}
Since there are no unit tests specific to NETSTANDARD in this repo, I added the unit test in my own test repo: https://github.com/meinsiedler/SerialPortStreamTest
Do you have any idea or hint, what the problem could be and how to fix it?
Best regards
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
OK, I’ll update the versions to 2.3.1 and prepare a new release and close this ticket when it’s in NuGet. Thanks all for your testing.
Hello @jcurl, I also had an issue with no data seen at the ReadAsync. I have tested your attached beta package and also found that it now works as expected. Thank you for the quick turn around.