Skip to content

Commit 93495b3

Browse files
hbraaschEllerbach
andauthored
Fix Direct Method bug where a formatting error occurs after 10 successfull messages (#61)
After 10 messages the [rid] changes to text [a], nor [10]. The conversion instruction fails when passed a non-numeric. The conversion has been corrected. When returning a response, a hex format value for [rid] also needs to be returned. A int => hex text conversion has been added to correct this. Co-authored-by: Laurent Ellerbach <[email protected]>
1 parent fc862d7 commit 93495b3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Azure.Devices.DeviceClient/DeviceClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void ClientMqttMsgReceived(object sender, MqttMsgPublishEventArgs e)
394394
const string C9PatternMainStyle = "<<Main>$>g__";
395395
string method = e.Topic.Substring(DirectMethodTopic.Length);
396396
string methodName = method.Substring(0, method.IndexOf('/'));
397-
int rid = Convert.ToInt32(method.Substring(method.IndexOf('=') + 1));
397+
int rid = Convert.ToInt32(method.Substring(method.IndexOf('=') + 1),16);
398398
_ioTHubStatus.Status = Status.DirectMethodCalled;
399399
_ioTHubStatus.Message = $"{method}/{message}";
400400
StatusUpdated?.Invoke(this, new StatusUpdatedEventArgs(_ioTHubStatus));
@@ -411,11 +411,11 @@ private void ClientMqttMsgReceived(object sender, MqttMsgPublishEventArgs e)
411411
try
412412
{
413413
var res = mt.Invoke(rid, message);
414-
_mqttc.Publish($"$iothub/methods/res/200/?$rid={rid}", Encoding.UTF8.GetBytes(res), MqttQoSLevel.AtLeastOnce, false);
414+
_mqttc.Publish($"$iothub/methods/res/200/?$rid={rid:X}", Encoding.UTF8.GetBytes(res), MqttQoSLevel.AtLeastOnce, false);
415415
}
416416
catch (Exception ex)
417417
{
418-
_mqttc.Publish($"$iothub/methods/res/504/?$rid={rid}", Encoding.UTF8.GetBytes($"{{\"Exception:\":\"{ex}\"}}"), MqttQoSLevel.AtLeastOnce, false);
418+
_mqttc.Publish($"$iothub/methods/res/504/?$rid={rid:X}", Encoding.UTF8.GetBytes($"{{\"Exception:\":\"{ex}\"}}"), MqttQoSLevel.AtLeastOnce, false);
419419
}
420420
}
421421
}

0 commit comments

Comments
 (0)