azureazure-functionsazure-functions-isolated

Unable to run azure durable orchestration function


I have a simple Azure Functions app, which includes HTTP trigger and a durable orchestration function, which the trigger invokes. This app runs fine when tested locally, but fails when it runs on Azure. The error coming from the orchestrator function is:

07-df83-4d2d-8023-ad4da1eed437, Duration=107ms)Unable to cast object of type 'System.String' to type 'Microsoft.Azure.WebJobs.Extensions.DurableTask.IDurableOrchestrationContext'.

Here is the code for the HTTP trigger:

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

public static class DurableHttpStart
{
    [FunctionName("DurableHttpStart")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("OrchestratorFunction", null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

And here is the code for the orchestrator function:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Extensions.Logging;
using SpreadsheetGear;

public static class OrchestratorFunction
{
    [FunctionName("OrchestratorFunction")]
    public static async Task<List<string>> RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var finalResult = new List<string>();
        return finalResult;
    }
}

This app is configured as "--dotnet-isolated"

Any ideas how this can be fixed?


Solution

  • As I have mentioned in the comment you are using in-process code in isolated environment. you need to use it in-process environment.

    I was also getting same error when I was using similar code in isolated model function app.

    My Code: Function1.cs:

    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 FunctionApp14
    {
        public static class Function1
        {
            [FunctionName("Function1")]
            public static async Task<List<string>> RunOrchestrator(
                [OrchestrationTrigger] IDurableOrchestrationContext context)
            {
                var outputs = new List<string>();
                return outputs;
            }
    
            [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}'.", instanceId);
    
                return starter.CreateCheckStatusResponse(req, instanceId);
            }
        }
    }
    

    FunctionApp14.csproj:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.12.0" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.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>
    </Project>
    
    

    When I deployed it to the function in In-process model it worked perfectly fine.

    As I mentioned in comment, Isolated model uses different packages as mentioned in this MSDoc.