使用 ArmClient 删除 Azure BotService 返回无效版本

问题描述 投票:0回答:1

当我尝试使用 ARM 客户端删除 azure 机器人服务时,我收到一条错误,指出有关

version 2023-09-15-preview is invalid
。示例代码如下:

var resourceGroupId = "ResourceGroupId";
var azureBotName = "BotName";
var armClient = new ArmClient(new DefaultAzureCredential());
var resourceGroup = armClient.GetResourceGroupResource(resourceGroupId);
var bot = await resourceGroup.GetGenericResourcesAsync($"resourceType eq 'Microsoft.BotService/botServices' and name eq '{azureBotName}'");
bot.First().DeleteAsync(WaitUntil.Completed);

该代码一直有效并成功删除了机器人,直到最近为止,并且没有改变。

c# azure botframework azure-resource-manager
1个回答
0
投票

Azure 最近更改了 management.azure.com 报告为有效的 API 版本,但新版本不正确。如果你运行powershell

Connect-AzAccount
((Get-AzResourceProvider -ProviderNamespace Microsoft.BotService).ResourceTypes | Where-Object ResourceTypeName -eq botServices).ApiVersions

您会看到

2023-09-15-preview
是最新报告的版本,但它不起作用,并且 https://learn.microsoft.com/en-us/azure/templates/microsoft.botservice/allversions 不起作用包括 2023 年 9 月 15 日预览。

您可以通过将 api 版本覆盖传递到 ArmClient 构造函数来解决此问题。所以如果你开始编码

var options = new ArmClientOptions();
options.SetApiVersion(new ResourceType("Microsoft/BotService"), "2022-09-15");
var armClient = new ArmClient(new DefaultAzureCredential, "SUBSCRIPTIONID", options);

然后删除就成功了。

© www.soinside.com 2019 - 2024. All rights reserved.