You need to make sure that you are using correct packages and also verify your code. I am sharing my code here which I have used for testing purpose.
I have following packages in **.csproj** file.
```csharp
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>_79076732</RootNamespace>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.7" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.18.1" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.4.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
```
I have created a separate file named **DurableTaskService** which has below given code.
```csharp
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask.Client;
namespace _79076732
{
public class DurableTaskService
{
private readonly DurableTaskClient _durableTaskClient;
public DurableTaskService(DurableTaskClient durableTaskClient)
{
_durableTaskClient = durableTaskClient;
}
public async Task<HttpResponseData> ExecuteAsync(HttpRequestData req)
{
string instanceId = await _durableTaskClient.ScheduleNewOrchestrationInstanceAsync("SayHelloEventOrchestrator");
Console.WriteLine($"Started orchestration with ID = {instanceId}");
var result = await _durableTaskClient.CreateCheckStatusResponseAsync(req, instanceId);
return result;
}
}
}
```
Then I registered it in **program.cs** file.
```csharp
using _79076732;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Azure.Functions.Worker;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.AddTransient<DurableTaskService, DurableTaskService>();
services.AddDurableTaskClient((builder) =>
{
builder.UseGrpc();
});
})
.Build();
host.Run();
```
Lastly, I am invoking **DurableTaskService** using a http triggered function.
```csharp
using Microsoft.DurableTask;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace _79076732
{
public class Function1
{
private readonly DurableTaskService _durableTaskService;
public Function1 (DurableTaskService durableTaskService)
{
_durableTaskService = durableTaskService;
}
[Function("SayHelloEventOrchestrator")]
public async Task<string> SayHelloOrchestrator([OrchestrationTrigger] TaskOrchestrationContext context)
{
var result = await context.CallActivityAsync<string>("SayHello", "Afreen");
return result;
}
[Function("SayHello")]
public string SayHello([ActivityTrigger] string name)
{
return $"Hello, {name}!";
}
[Function("StartOrchestration")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, FunctionContext executionContext)
{
var logger = executionContext.GetLogger("StartOrchestrationFunction");
logger.LogInformation("Starting orchestration...");
var orchestrationResult = await _durableTaskService.ExecuteAsync(req);
return orchestrationResult;
}
}
}
```
By doing the above given steps, I am able to get the expected response.
```csharp
Azure Functions Core Tools
Core Tools Version: 4.0.6280 Commit hash: N/A +421f0144b42047aa289ce691dc6db4fc8b6143e6 (64-bit)
Function Runtime Version: 4.834.3.22875
[2024-10-11T08:04:13.447Z] Found C:\Users\*****\79076732\79076732.csproj. Using for user secrets file configuration.
[2024-10-11T08:04:17.440Z] Azure Functions .NET Worker (PID: 19544) initialized in debug mode. Waiting for debugger to attach...
[2024-10-11T08:04:17.497Z] Worker process started and initialized.
Functions:
StartOrchestration: [GET,POST] http://localhost:7230/api/StartOrchestration
SayHello: activityTrigger
SayHelloEventOrchestrator: orchestrationTrigger
For detailed output, run func with --verbose flag.
[2024-10-11T08:04:22.487Z] Host lock lease acquired by instance ID '0000000000000000000000000D2022A4'.
[2024-10-11T08:04:30.630Z] Executing 'Functions.StartOrchestration' (Reason='This function was programmatically called via the host APIs.', Id=70ee6cb7-000e-462d-b6b0-db15a0d812a2)
[2024-10-11T08:04:31.024Z] Scheduling new SayHelloEventOrchestrator orchestration with instance ID 'c626f9f4c2904356aa9fce247ac270ee' and 0 bytes of input data.
[2024-10-11T08:04:31.024Z] Starting orchestration...
[2024-10-11T08:04:31.226Z] Started orchestration with ID = c626f9f4c2904356aa9fce247ac270ee
[2024-10-11T08:04:31.301Z] Executed 'Functions.StartOrchestration' (Succeeded, Id=70ee6cb7-000e-462d-b6b0-db15a0d812a2, Duration=712ms)
[2024-10-11T08:04:31.320Z] Executing 'Functions.SayHelloEventOrchestrator' (Reason='(null)', Id=fc774ab1-d7fe-42e1-bc68-45c275bcd0f8)
[2024-10-11T08:04:31.508Z] Executed 'Functions.SayHelloEventOrchestrator' (Succeeded, Id=fc774ab1-d7fe-42e1-bc68-45c275bcd0f8, Duration=202ms)
[2024-10-11T08:04:31.567Z] Executing 'Functions.SayHello' (Reason='(null)', Id=f376e280-6741-4eda-9fe2-4d43f79ff1f9)
[2024-10-11T08:04:31.582Z] Executed 'Functions.SayHello' (Succeeded, Id=f376e280-6741-4eda-9fe2-4d43f79ff1f9, Duration=17ms)
[2024-10-11T08:04:31.651Z] Executing 'Functions.SayHelloEventOrchestrator' (Reason='(null)', Id=f52075b5-c10b-4f67-af85-bd933754b8ab)
[2024-10-11T08:04:31.685Z] Executed 'Functions.SayHelloEventOrchestrator' (Succeeded, Id=f52075b5-c10b-4f67-af85-bd933754b8ab, Duration=36ms)
```
![enter image description here](https://i.imgur.com/MDnyNqh.png)
![enter image description here](https://i.imgur.com/1F7AfFL.png)
>Call Stack: System.Threading.Tasks.TaskCanceledException
This could be due timeout or a cancellation of an asynchronous operation.
To resolve this error, use **functionTimeout** attribute in host.json and debug the function:
**host.json:**
```json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
"functionTimeout": "00:30:00"
}
```
I have tested the same code with .NET 8 Isolated Azure function in my environment:
```csharp
public class Function1
{
private readonly ILogger<Function1> _logger;
public Function1(ILogger<Function1> logger)
{
_logger = logger;
}
[Function("Function1")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route ="ready")] HttpRequest req)
{
return new OkObjectResult("ok");
}
}
```
**.csproj:**
```
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
```
**Able to test without any issues:**
![enter image description here](https://i.imgur.com/Ple23tr.png)
- **Update the packages to the latest compatible versions:**
[![enter image description here][1]][1]
[1]: https://i.sstatic.net/M2R3b.png