Unused parameter in WithTryPrivate causing client to send incorrect version byte in header. #2125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #2122
As described in the issue, the MQTTNet.Client sends incorrect version in the connect header, causing the server to respond with an unsupported protocol exception.
Digging into the encoding code, it turns out the issue is rooted in the EncodeConnectPacket method in MqttV3PacketFormatter.
If TryPrivate is true (default), a bitwise OR operation is applied to the protocol version (I don't know why this is done).
This results in the connect header containing an incorrect version:
(hex): 10 df 04 00 06 4d 51 49 73 64 70 (83) 82 00 0f 00
Instead of the expected
(hex): 10 df 04 00 06 4d 51 49 73 64 70 (03) 82 00 0f 00
After fixing the unused parameter in WithTryPrivate and using .WithTryPrivate(false), the connection is successful and no longer throws an UnsupportedProtocolVersion exception.