Azure / Azure/azure-iot-sdk-csharp

[Bug Report] Cannot invoke direct methods with payload in IotEdge devices.

Open
#3,381 8 comments 0 reactions 0 assignees View on GitHub
bug IoTSDK
Dominant language
C#
Stars
477
Forks
492
Avg merge
9h 55m
Merged PRs (30d)
2

Description

# Context

- **OS, version, SKU and CPU architecture used:Windows 10 Desktop x64
- **Application's .NET Target Framework : .NET8.0-RC2
- **Device: Laptop
- **SDK version used: 2.0.0-preview007
- IoT Edge version: 1.4.23

## Description of the issue
Cannot invoke direct methods with payload in IotEdge devices.

## Code sample exhibiting the issue
```csharp
var serviceClient = new IotHubServiceClient("HostName=***");
string json =
"{\"schemaVersion\": \"1.0\",\"items\": [{\"id\": \"module\",\"filter\": {\"tail\": 3,\"since\": \"10m\"}}],\"encoding\": \"none\",\"contentType\": \"text\"}";
DirectMethodServiceRequest request = new("GetModuleLogs")
{
Payload = Encoding.UTF8.GetBytes(json)
};
var result = await serviceClient.DirectMethods.InvokeAsync("deviceId", "$edgeAgent", request);
```
## Console log of the issue
{"message":"Error parsing command payload because of error - Error converting value \"eyJzY2hlbWFWZXJzaW9uIjogIjEuMCIsIml0ZW1zIjogW3siaWQiOiAiaW90ZWRnZWdhdGV3YXkiLCJmaWx0ZXIiOiB7InRhaWwiOiAzLCJzaW5jZSI6ICIxMG0ifX1dLCJlbmNvZGluZyI6ICJub25lIiwiY29udGVudFR5cGUiOiAidGV4dCJ9\" to type 'Microsoft.Azure.Devices.Edge.Agent.Core.Requests.ModuleLogsRequest'. Path '', line 1, position 186."}

Contributor guide

Open the contributing guide

Research direction

Start with the DirectMethodServiceRequest payload construction and the DirectMethods.InvokeAsync call shown in the report, then compare the sent payload with the IoT Edge console error. Reproduce the request against an IoT Edge device and trace how the SDK encodes the payload; done means a payload-bearing direct method is accepted and the reported conversion error no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.