[英]function app can't send message to event grid: The given key '1' was not present in the dictionary
I have a function app with a function that sends message to event grid and a function in this same function app subscribed to this event grid topic.我有一个 function 应用程序,其中一个 function 将消息发送到事件网格,而同一个 function 应用程序中的一个 function 订阅了这个事件网格主题。 The function app that sends message to event grid uses key 1 to auth .向事件网格发送消息的 function 应用程序使用密钥 1 进行身份验证。
//Name of the endpoint of Event grid topic
string topicEndpoint = transformAlgoSendRMessage_TopicEP;
//Creating client to publish events to eventgrid topic
AzureKeyCredential credential = new AzureKeyCredential(eventGridTopic_Key);
EventGridPublisherClient client = new EventGridPublisherClient(new Uri(topicEndpoint), credential);
//Creating a sample event with Subject, Eventtype, dataVersion and data
EventGridEvent egEvent = new EventGridEvent("TransformTelemetry", "TransformAlgorithm.broadcastTransform", "1.0", machinePartTransformTelemetry);
// Send the event
try
{
await client.SendEventAsync(egEvent);
log.LogInformation("SendRTransformMessage sent transformdata - PosX:" + machinePartTransformTelemetry[1]);
}
catch (Exception e)
{
log.LogError("Failed to send SendRTransformMessage. " + e.Message);
}
Code at execution of await client.SendEventAsync(egEvent) gives me error:执行 await client.SendEventAsync(egEvent) 时的代码给我错误:
The given key '1' was not present in the dictionary.
I get the key using the azure portal copy to clipboard widget and paste in code.我使用 azure 门户复制到剪贴板小部件并粘贴代码来获取密钥。 I also tried using powershell which confirmed the key.我还尝试使用确认密钥的 powershell。
az eventgrid topic key list --name eventgridtopicname --resource-group myresourcegroup --query "key1"
I'm using Azure.Messaging.EventGrid v4.12.0 and also tried Microsoft.Azure.Eventgrid v.3.2.0, I'm on VS2022 with latest update.我正在使用Azure.Messaging.EventGrid v4.12.0并且还尝试了 Microsoft.Azure.Eventgrid v.3.2.0,我在 VS2022 上安装了最新更新。
This doesn't look like an issue of whether the Acces Key was valid or not, and you've ruled it out by verifying via CLI command in Powershell.这看起来不像是 Acces Key 是否有效的问题,您已经通过 Powershell 中的 CLI 命令验证排除了它。
The "key" in the error message is likely in reference to the missing item in the dictionary type, which I suspect is this: machinePartTransformTelemetry[1]
错误消息中的“键”可能是指字典类型中缺少的项目,我怀疑是这样的: machinePartTransformTelemetry[1]
More context on the error message: The given key was not present in the dictionary.有关错误消息的更多上下文:字典中不存在给定的键。 Which key? 哪把钥匙?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.