Skip to content

SerialStream.Windows.cs treats dwMaxBaud as a baud rate when it's defined as an enum #119105

@emrsn-mspant

Description

@emrsn-mspant

Description

COMMPROP describes dwMaxBaud as max baud rate in a table of enumerations but the code in SerialStream.Windows.cs compares the max baud rate directly to the baud rate in several place. If commProp.dwMaxBaud is 64 (1200 bps) and baudRate is 1200 bps, the exception is thrown that it's out of range.

Lines 626-627
if (_commProp.dwMaxBaud != 0 && baudRate > _commProp.dwMaxBaud) throw new ArgumentOutOfRangeException(nameof(baudRate), SR.Format(SR.Max_Baud,_commProp.dwMaxBaud));

Reproduction Steps

  1. Find a com port device that has a max baud rate defined as an enum
  2. Attempt to open a com port created with the max baud rate.
  3. Observe the exception thrown.
    `
    // COM6 max baud rate is 64, which is enum for 1200.
    using (var sp = new SerialPort("COM6", 1200))
    {
    sp.Open(); // throws exception that max baud rate is 64.
    }

`

Expected behavior

Successful opening of com port when dwMaxBaud is not zero by converting the dwMaxBaud enum to a baud rate value.

Actual behavior

Exception thrown because it's comparing an enum to a value

Regression?

No idea.

Known Workarounds

For the com port device we have this issue, it does work if setting the baud rate to 64 since only one baud rate is valid for the device.

Configuration

.netstandard20
Windows 11
Any CPU (x64)

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IO.Portshelp wanted[up-for-grabs] Good issue for external contributorsneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions