gpt4 book ai didi

c# - Azure 函数在使用设备客户端 SDK 发送 D2C 消息时引发错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:53 25 4
gpt4 key购买 nike

我有一个 Even hub Triggered azure 函数,我需要从中向 IoT hub 发送 D2C 消息。

我已经从 NuGet 安装了 Microsoft.Azure.Devices.Client。但它在 deviceClient.SendEventAsync(iotmessage) 发送 D2C 消息时抛出以下错误。

Error: Unable to find assembly 'Validation, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7'. Are you missing a private assembly file? Error occured - Could not load file or assembly 'Validation, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7' or one of its dependencies. The system cannot find the file specified.

代码:

[FunctionName("TelemetryProcessor")]
public static async Task Run([EventHubTrigger("telemetry", ConsumerGroup = "$Default", Connection = "TelemetryEventHubConnection")]string telemetryMessage, TraceWriter log)
{
try
{
var message = JsonConvert.DeserializeObject<IoTMessage>(telemetryMessage);
if (message.MessageType == MessageType.TLM)
{
var device = GetiDeviceById(message.SenderId);
if (device != null)
{
using (var deviceClient = DeviceClient.Create("iothub.azure-devices.net",
new DeviceAuthenticationWithRegistrySymmetricKey(device.Id, device.Key), TransportType.Mqtt))
{
message.MessageType = MessageType.TLM_HUB;
var iotmessage = new Message(Encoding.ASCII.GetBytes(message.ToString()));
await deviceClient.SendEventAsync(iotmessage);
}
}
else
{
log.Error($"Device Not Found");
}
}
}
catch (Exception ex)
{
log.Error($"Error occured - {ex.Message}");
}
}

最佳答案

我遇到了完全相同的问题,这就是我如何让它工作的。

为函数编辑/创建 project.json 文件并包含特定版本的验证。我还发现我在使用 Json serializable 时遇到了问题,直到我也指定了早期版本的 Newtonsoft.Json。

{
"frameworks": {
"net46":{
"dependencies": {
"microsoft.azure.devices.client": "1.6.1",
"Newtonsoft.Json": "9.0.1",
"validation": "[2.2.8]"
}
}
}
}

关于c# - Azure 函数在使用设备客户端 SDK 发送 D2C 消息时引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48378800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com