DurableTask nuget 包升级到 2.0.0 版本后找不到 Azure 持久函数编排客户端
Azure durable function orchestration client cannot be found when the DurableTask nuget package is upgraded to version 2.0.0
定义一个队列触发函数,如下例:
public async Task OrchestratorAsync(
[QueueTrigger("my-queue", Connection = "")]string payload,
[OrchestrationClient] DurableOrchestrationClient orchestrationClient)
{
//Do something
}
csproj 文件看起来像以下详细信息并且编译成功:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
</ItemGroup>
</project>
当我将 Microsoft.Azure.WebJobs.Extensions.DurableTask
升级到版本 2.0.0 时,编译器会抛出无法找到 OrchestrationClient 和 DurableOrchestrationClient 的错误。所以我们坚持使用 1.8.2 版!这个问题的解决方案是什么?
注意:这个问题在 VS 2019 中很容易重现。让它搭建一个函数项目,创建另一个函数作为持久协调器,调整 csproj 文件并将 DurableTask nuget 包版本从默认 1.8.2.
我已经重现了你的错误,我解决了这个问题。
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace _11111fc
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context,
[DurableClient] IDurableOrchestrationClient orchestrationClient)
{
var outputs = new List<string>();
// Replace "hello" with the name of your Durable Activity Function.
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Tokyo"));
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Seattle"));
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
[FunctionName("Function1_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log)
{
log.LogInformation($"Saying hello to {name}.");
return $"Hello {name}!";
}
[FunctionName("Function1_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
[DurableClient]IDurableOrchestrationClient starter,
ILogger log)
{
// Function input comes from the request content.
string instanceId = await starter.StartNewAsync("Function1", null);
log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
}
}
解法:
将 [OrchestrationClient] 更改为 [DurableClient]。看看this。
请注意 Durable Functions v2.0.0-beta2 Release
中的重大更改,OrchestrationClient
已重命名。
我这边一切正常。请在你这边试一试。
定义一个队列触发函数,如下例:
public async Task OrchestratorAsync(
[QueueTrigger("my-queue", Connection = "")]string payload,
[OrchestrationClient] DurableOrchestrationClient orchestrationClient)
{
//Do something
}
csproj 文件看起来像以下详细信息并且编译成功:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
</ItemGroup>
</project>
当我将 Microsoft.Azure.WebJobs.Extensions.DurableTask
升级到版本 2.0.0 时,编译器会抛出无法找到 OrchestrationClient 和 DurableOrchestrationClient 的错误。所以我们坚持使用 1.8.2 版!这个问题的解决方案是什么?
注意:这个问题在 VS 2019 中很容易重现。让它搭建一个函数项目,创建另一个函数作为持久协调器,调整 csproj 文件并将 DurableTask nuget 包版本从默认 1.8.2.
我已经重现了你的错误,我解决了这个问题。
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace _11111fc
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context,
[DurableClient] IDurableOrchestrationClient orchestrationClient)
{
var outputs = new List<string>();
// Replace "hello" with the name of your Durable Activity Function.
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Tokyo"));
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "Seattle"));
outputs.Add(await context.CallActivityAsync<string>("Function1_Hello", "London"));
// returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
return outputs;
}
[FunctionName("Function1_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log)
{
log.LogInformation($"Saying hello to {name}.");
return $"Hello {name}!";
}
[FunctionName("Function1_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
[DurableClient]IDurableOrchestrationClient starter,
ILogger log)
{
// Function input comes from the request content.
string instanceId = await starter.StartNewAsync("Function1", null);
log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
}
}
解法:
将 [OrchestrationClient] 更改为 [DurableClient]。看看this。
请注意 Durable Functions v2.0.0-beta2 Release
中的重大更改,OrchestrationClient
已重命名。
我这边一切正常。请在你这边试一试。