Skip to content

"Length cannot be less than zero" error on ReadLineAsync #1

@bobasaurus

Description

@bobasaurus

I'm getting the following error when trying to asynchronously read a line after writing a command:

System.ArgumentOutOfRangeException: 'Length cannot be less than zero. (Parameter 'length')'

This is the code that triggers the error:

serialPort = new SerialPort(portName: port, baudRate: 9600, parity: Parity.Even, dataBits: 7, stopBits: StopBits.One);
serialPort.NewLine = "\r";
serialPort.ReadTimeout = 1000;
serialPort.WriteTimeout = 1000;
serialPort.Open();

await serialPort.WriteLineAsync("R0");
var result = await serialPort.ReadLineAsync();

If I change the last line to a synchronous ReadLine call it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions