Skip to content

Durable Functions work correctly locally, but not when deployed? #7828

Open

Description

@VistianOpenSource

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Introduction of the 'standard' sample durable function code (SayHello , which calls activities to say hello for Tokyo , London and Seattle) works fine locally with either a AzureStorage provided as the HostStorage OR with an environment variable for AzureWebJobStorage being provided (which references an existing Azure storage container).

However, when deployed using the inbuilt deploy option within Visual Studio, neither the solution which references the AzureStorage or the existing storage via the environment variable works.

With the environment variable, the azure functions project does startup when deployed, and non durable functions can be successfully invoked, but upon first invocation of a http endpoint which is used to instigate a durable orchestration, one gets an exception.

Expected Behavior

To function as it does when executed locally.

Steps To Reproduce

Take an existing minimal functional Aspire Azure Functions project.

Add the existing sample durable SayHello function code to it.

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;

namespace FunctionApp2
{
    public static class Function
    {
        [Function(nameof(Function))]
        public static async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] TaskOrchestrationContext context)
        {
            ILogger logger = context.CreateReplaySafeLogger(nameof(Function));
            logger.LogInformation("Saying hello.");
            var outputs = new List<string>();

            // Replace name and input with values relevant for your Durable Functions Activity
            outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo"));
            outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Seattle"));
            outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "London"));

            // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
            return outputs;
        }

        [Function(nameof(SayHello))]
        public static string SayHello([ActivityTrigger] string name, FunctionContext executionContext)
        {
            ILogger logger = executionContext.GetLogger("SayHello");
            logger.LogInformation("Saying hello to {name}.", name);
            return $"Hello {name}!";
        }

        [Function("Function_HttpStart")]
        public static async Task<HttpResponseData> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
            [DurableClient] DurableTaskClient client,
            FunctionContext executionContext)
        {
            ILogger logger = executionContext.GetLogger("Function_HttpStart");

            // Function input comes from the request content.
            string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
                nameof(Function));

            logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

            // Returns an HTTP 202 response with an instance management payload.
            // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
            return await client.CreateCheckStatusResponseAsync(req, instanceId);
        }
    }
}

Add a call to

builder.ConfigureDurableExtension();

Publish aspire solution, and attempt to invoke the function api/Function_HttpStart

Observe contents of log.

Exceptions (if any)

When just running with the added azure storage this exception is seen

2025-02-28T10:24:30 stdout F WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
12025-02-28T10:24:31 stdout F info: Host.Triggers.DurableTask[0]
22025-02-28T10:24:31 stdout F Using the default storage provider: AzureStorage.
32025-02-28T10:24:31 stdout F fail: Host.Startup[515]
42025-02-28T10:24:31 stdout F A host error has occurred during startup operation '7dd46ca3-8a42-4f64-aaee-41927109e533'.
52025-02-28T10:24:31 stdout F System.InvalidOperationException: Unable to find matching constructor while trying to create an instance of TableServiceClient.
62025-02-28T10:24:31 stdout F Expected one of the follow sets of configuration parameters:
72025-02-28T10:24:31 stdout F 1. endpoint
82025-02-28T10:24:31 stdout F 2. endpoint, credential:signature
92025-02-28T10:24:31 stdout F 3. endpoint, credential:accountName, credential:accountKey
102025-02-28T10:24:31 stdout F 4. connectionString
112025-02-28T10:24:31 stdout F 5. endpoint
122025-02-28T10:24:31 stdout F
132025-02-28T10:24:31 stdout F Found the following configuration keys: queueServiceUri, blobServiceUri
142025-02-28T10:24:31 stdout F at Microsoft.Extensions.Azure.ClientFactory.CreateClient(Type clientType, Type optionsType, Object options, IConfiguration configuration, TokenCredential credential)
152025-02-28T10:24:31 stdout F at Microsoft.Azure.WebJobs.Extensions.DurableTask.Storage.StorageServiceClientProvider`3.CreateClient(TClientOptions options) in /_/src/WebJobs.Extensions.DurableTask/Storage/StorageServiceClientProvider.cs:line 50

When ran with an environment variable for the storage specified (and also now specified in the hosts.json file in the extensions section) , one gets this :

2025-02-28T10:45:19 stdout F info: Host.General[337]
2282025-02-28T10:45:19 stdout F Host lock lease acquired by instance ID '00000000000000000000000073B4F8B5'.
2292025-02-28T10:47:14 stdout F info: Function.Function_HttpStart[1]
2302025-02-28T10:47:14 stdout F Executing 'Functions.Function_HttpStart' (Reason='This function was programmatically called via the host APIs.', Id=e15a30be-1822-4dc4-ac04-3550aec1f917)
2312025-02-28T10:47:14 stdout F fail: Function.Function_HttpStart[3]
2322025-02-28T10:47:14 stdout F Executed 'Functions.Function_HttpStart' (Failed, Id=e15a30be-1822-4dc4-ac04-3550aec1f917, Duration=39ms)
2332025-02-28T10:47:14 stdout F Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.Function_HttpStart
2342025-02-28T10:47:14 stdout F ---> System.InvalidOperationException: Webhooks are not configured. This may occur if the environment variable WEBSITE_HOSTNAME is not set (should be automatically set for Azure Functions). Try setting it to the appropiate URI to reach your app. For example: the DNS name of the app, or a value of the form :.
2352025-02-28T10:47:14 stdout F at Microsoft.Azure.WebJobs.Extensions.DurableTask.HttpApiHandler.GetWebhookUri() in //src/WebJobs.Extensions.DurableTask/HttpApiHandler.cs:line 1246
2362025-02-28T10:47:14 stdout F at Microsoft.Azure.WebJobs.Extensions.DurableTask.HttpApiHandler.GetUniversalQueryStrings() in /
/src/WebJobs.Extensions.DurableTask/HttpApiHandler.cs:line 1141
2372025-02-28T10:47:14 stdout F at Microsoft.Azure.WebJobs.Extensions.DurableTask.BindingHelper.DurableOrchestrationClientToString(IDurableOrchestrationClient client, DurableClientAttribute at

If i specify an environment variable for WEBSITE_HOSTNAME which is that for the functions container, I get this exception

WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
12025-02-28T11:09:23 stdout F info: Host.Triggers.DurableTask[0]
22025-02-28T11:09:23 stdout F Using the default storage provider: AzureStorage.
32025-02-28T11:09:24 stdout F info: Host.Triggers.Warmup[0]
42025-02-28T11:09:24 stdout F Initializing Warmup Extension.
52025-02-28T11:09:24 stdout F fail: Host.Startup[515]
62025-02-28T11:09:24 stdout F A host error has occurred during startup operation 'a03fd3a3-7d9d-4251-b6fb-5b56451aac1e'.
72025-02-28T11:09:24 stdout F System.UnauthorizedAccessException: Access to the path '/azure-functions-host/Secrets' is denied.
82025-02-28T11:09:24 stdout F ---> System.IO.IOException: Permission denied
92025-02-28T11:09:24 stdout F --- End of inner exception stack trace ---
102025-02-28T11:09:24 stdout F at System.IO.FileSystem.CreateParentsAndDirectory(String fullPath, UnixFileMode unixCreateMode)
112025-02-28T11:09:24 stdout F at System.IO.FileSystem.CreateDirectory(String fullPath, UnixFileMode unixCreateMode)
122025-02-28T11:09:24 stdout F at System.IO.Directory.CreateDirectory(String path)
132025-02-28T11:09:24 stdout F at System.IO.Abstractions.DirectoryWrapper.CreateDirectory(String path)
142025-02-28T11:09:24 stdout F at Microsoft.Azure.WebJobs.Script.FileUtility.EnsureDirectoryExists(String path) in /src/azure-functions-host/src/WebJobs.Script/Extensions/FileUtility.cs:line 40
152025-02-28T11:09:24 stdout F at Microsoft.Azure.WebJobs.Script.WebHost.BaseSecretsRepository.InitializeSentinelDirectoryAndWatcher() in /src/azure-functions-host/src/WebJobs.Script.WebHost/Security/KeyManagement/BaseSecretsRepository.cs:line 113
162025-02-28T11:09:24 stdout F at Microsoft.Azure.WebJobs.Script.WebHost.BaseSecretsRepository..ctor(String secretsSentinelFilePath, ILogger logger, IEnvironment environment) in /src/azure-functions-host/src/WebJobs.Script.WebHost/Security/KeyManagement/BaseSecretsRepository.cs:line 38
172025-02-28T11:09:24 stdout F at Microsoft.Azure.WebJobs.Script.WebHost.BlobStorageSecretsRepository..ctor(String secretSentinelDirectoryPath, String accountConnection, String siteSlotName, ILogger logger, IEnvironment environment, IAzureBlobStorageProvider azureBlobStorageProvider)

.NET Version info

.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.69179adf
MSBuild version: 17.13.8+cbc39bea8

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.200\

.NET workloads installed:
[aspire]
Installation Source: VS 17.13.35818.85
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.2
Architecture: x64
Commit: 80aa709f5d

.NET SDKs installed:
9.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Anything else?

Visual Studio: 17.13.1
Targeting : net8.0

Activity

  1. added
    area-integrations
    azure
    on Feb 28, 2025
  2. davidfowl commented on Feb 28, 2025

    @davidfowl
    Collaborator

    Where is the apphost code?

  3. VistianOpenSource commented on Feb 28, 2025

    @VistianOpenSource
    Author

    Where is the apphost code?

    Apologies

    using Microsoft.Extensions.Hosting;
    using static System.Net.WebRequestMethods;
    
    var builder = DistributedApplication.CreateBuilder(args);
    
    var storage = builder.AddAzureStorage("storage")
                         .RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent)) ;
    
    builder.AddAzureFunctionsProject<Projects.FunctionApp2>("function-csharp-app").
        WithHostStorage(storage).
        WithExternalHttpEndpoints();
    
    
    builder.AddAzureFunctionsProject<Projects.FunctionAppFSharp>("function-fsharp-app").
        WithEnvironment("AzureWebJobsStorage", "DefaultEndpointsProtocol=https;AccountName=durablefunctions2025;AccountKey=***REMOVED***;EndpointSuffix=core.windows.net").
        WithEnvironment("WEBSITE_HOSTNAME", "function-fsharp-app.redgrass-3f98d8ed.ukwest.azurecontainerapps.io").
        WithExternalHttpEndpoints();
    
    
    builder.Build().Run();
    
  4. davidfowl commented on Feb 28, 2025

    @davidfowl
    Collaborator

    I would remove these customizations and stick to the happy path.

        WithEnvironment("AzureWebJobsStorage", "DefaultEndpointsProtocol=https;AccountName=durablefunctions2025;AccountKey=***REMOVED***;EndpointSuffix=core.windows.net").
        WithEnvironment("WEBSITE_HOSTNAME", "function-fsharp-app.redgrass-3f98d8ed.ukwest.azurecontainerapps.io").
    

    Then we can look at the errors and figure out what is the real issue.

    I believe Safia Abdalla (@captainsafia) was looking at durable functions earlier this month.

  5. VistianOpenSource commented on Feb 28, 2025

    @VistianOpenSource
    Author

    I would remove these customizations and stick to the happy path.

        WithEnvironment("AzureWebJobsStorage", "DefaultEndpointsProtocol=https;AccountName=durablefunctions2025;AccountKey=***REMOVED***;EndpointSuffix=core.windows.net").
        WithEnvironment("WEBSITE_HOSTNAME", "function-fsharp-app.redgrass-3f98d8ed.ukwest.azurecontainerapps.io").
    

    Then we can look at the errors and figure out what is the real issue.

    I believe @captainsafia was looking at durable functions earlier this month.

    Okay, so I removed the F# project (I primarily work in F#, but when it wasn't working I spun up a C# project as well since there is generally better out of the box support for C#). Now apphost looks like:

    using Aspire.Hosting;
    using Microsoft.Extensions.Hosting;
    using static System.Net.WebRequestMethods;
    
    var builder = DistributedApplication.CreateBuilder(args);
    
    var storage = builder.AddAzureStorage("storage")
                         .RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent)) ;
    
    builder.AddAzureFunctionsProject<Projects.FunctionApp2>("function-csharp-app").
        WithHostStorage(storage).
        WithExternalHttpEndpoints();
    
    builder.Build().Run();
    

    The main file of the azure function project looks like this:

    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Azure.Functions.Worker.Builder;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Microsoft.Azure.Functions.Worker.Extensions.DurableTask;
    
    
    var builder = FunctionsApplication.CreateBuilder(args);
    
    builder.AddServiceDefaults();
    
    
    builder.ConfigureFunctionsWebApplication();
    
    
    // Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4.
    // builder.Services
    //     .AddApplicationInsightsTelemetryWorkerService()
    //     .ConfigureFunctionsApplicationInsights();
    
    
    builder.ConfigureDurableExtension();
    
    builder.Build().Run();
    

    Deployed, to azure, console log for the azure function project looks like:

    2025-02-28T15:31:51 stdout F WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
    2025-02-28T15:31:51 stdout F info: Host.Triggers.DurableTask[0]
    2025-02-28T15:31:51 stdout F       Using the default storage provider: AzureStorage.
    2025-02-28T15:31:51 stdout F fail: Host.Startup[515]
    2025-02-28T15:31:51 stdout F       A host error has occurred during startup operation 'bc2e83c7-5563-4327-a27c-e862335a0397'.
    2025-02-28T15:31:51 stdout F       System.InvalidOperationException: Unable to find matching constructor while trying to create an instance of TableServiceClient.
    2025-02-28T15:31:51 stdout F       Expected one of the follow sets of configuration parameters:
    2025-02-28T15:31:51 stdout F       1. endpoint
    2025-02-28T15:31:51 stdout F       2. endpoint, credential:signature
    2025-02-28T15:31:51 stdout F       3. endpoint, credential:accountName, credential:accountKey
    2025-02-28T15:31:51 stdout F       4. connectionString
    2025-02-28T15:31:51 stdout F       5. endpoint
    2025-02-28T15:31:51 stdout F       
    2025-02-28T15:31:51 stdout F       Found the following configuration keys: queueServiceUri, blobServiceUri
    2025-02-28T15:31:51 stdout F          at Microsoft.Extensions.Azure.ClientFactory.CreateClient(Type clientType, Type optionsType, Object options, IConfiguration configuration, TokenCredential credential)
    2025-02-28T15:31:51 stdout F          at Microsoft.Azure.WebJobs.Extensions.DurableTask.Storage.StorageServiceClientProvider`3.CreateClient(TClientOptions options) in /_/src/WebJobs.Extensions.DurableTask/Storage/StorageServiceClientProvider.cs:line 50
    2025-02-28T15:31:51 stdout F          at DurableTask.AzureStorage.Storage.AzureStorageClient..ctor(AzureStorageOrchestrationServiceSettings settings) in /_/src/DurableTask.AzureStorage/Storage/AzureStorageClient.cs:line 58
    2025-02-28T15:31:51 stdout F          at DurableTask.AzureStorage.AzureStorageOrchestrationService..ctor(AzureStorageOrchestrationServiceSettings settings, IOrchestrationServiceInstanceStore customInstanceStore) in /_/src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs:line 116
    2025-02-28T15:31:51 stdout F          at Microsoft.Azure.WebJobs.Extensions.DurableTask.AzureStorageDurabilityProviderFactory.GetDurabilityProvider() in /_/src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProviderFactory.cs:line 130
    2025-02-28T15:31:51 stdout F          at Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskExtension..ctor(IOptions`1 options, ILoggerFactory loggerFactory, INameResolver nameResolver, IEnumerable`1 orchestrationServiceFactories, IApplicationLifetimeWrapper hostLifetimeService, IDurableHttpMessageHandlerFactory durableHttpMessageHandlerFactory, ILifeCycleNotificationHelper lifeCycleNotificationHelper, IMessageSerializerSettingsFactory messageSerializerSettingsFactory, IPlatformInformation platformInformationService, IErrorSerializerSettingsFactory errorSerializerSettingsFactory, IWebHookProvider webhookProvider, ITelemetryActivator telemetryActivator) in /_/src/WebJobs.Extensions.DurableTask/DurableTaskExtension.cs:line 133
    2025-02-28T15:31:51 stdout F          at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
    
    

    The host.json in the Azure functions project, only contains:

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          },
          "enableLiveMetricsFilters": true
        }
      }
    }
    

    The project which I'm looking to move from a non isolated implementation of durable functions, to an isolated one under Aspire, contained additional details in the host.json, including names of enviroment strings for storage.

  6. mobackanandj commented on Mar 4, 2025

    @mobackanandj

    Hi Team,
    Any update on this issue ? as issue is Durable Functions work correctly locally, but not when deployed?

  7. mobackanandj commented on Mar 6, 2025

    @mobackanandj

    Hi Team,

    Please update the Function_HttpStart function to inject DurableTaskClient through the constructor instead of passing it as a parameter. The ScheduleNewOrchestrationInstanceAsync method should be called from the injected client.

    Updated Function with Constructor Injection:

    public class Function_HttpStart
    {
        private readonly DurableTaskClient _client;
    
        public Function_HttpStart(DurableTaskClient client)
        {
            _client = client;
        }
    
        [Function("Function_HttpStart")]
        public async Task<HttpResponseData> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
            FunctionContext executionContext)
        {
            ILogger logger = executionContext.GetLogger("Function_HttpStart");
    
            // Start a new orchestration
            string instanceId = await _client.ScheduleNewOrchestrationInstanceAsync(nameof(Function_HttpStart));
            logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
    
            return await _client.CreateCheckStatusResponseAsync(req, instanceId);
        }
    }

    Update in Program.cs:

    services.AddDurableTaskClient(builder =>
    {
        builder.UseGrpc();
    });
  8. davidfowl commented on Mar 7, 2025

    @davidfowl
    Collaborator

    Did you get it working?

  9. mobackanandj commented on Mar 7, 2025

    @mobackanandj

    Yes! After implementing these changes, the DurableTaskClient is now successfully invoking _client.ScheduleNewOrchestrationInstanceAsync. Give it a try!

  10. VistianOpenSource commented on Mar 7, 2025

    @VistianOpenSource
    Author

    Well, i've just made the changes, and, as per before, it works locally for me, but not when deployed to Azure.

    When deployed, I get exactly the same error upon startup as I did previously, namely:

    2025-03-07T08:32:28 stdout F info: Host.Triggers.DurableTask[0]
    2025-03-07T08:32:28 stdout F       Using the default storage provider: AzureStorage.
    2025-03-07T08:32:29 stdout F Hosting environment: Production
    2025-03-07T08:32:29 stdout F Content root path: /azure-functions-host
    2025-03-07T08:32:29 stdout F Now listening on: http://[::]:8080
    2025-03-07T08:32:29 stdout F Application started. Press Ctrl+C to shut down.
    2025-03-07T08:32:29 stdout F info: Host.Triggers.DurableTask[0]
    2025-03-07T08:32:29 stdout F       Using the default storage provider: AzureStorage.
    2025-03-07T08:32:29 stdout F fail: Host.Startup[515]
    2025-03-07T08:32:29 stdout F       A host error has occurred during startup operation '450b8ff4-200b-4b66-a429-13b918f7267a'.
    2025-03-07T08:32:29 stdout F       System.InvalidOperationException: Unable to find matching constructor while trying to create an instance of TableServiceClient.
    2025-03-07T08:32:29 stdout F       Expected one of the follow sets of configuration parameters:
    2025-03-07T08:32:29 stdout F       1. endpoint
    2025-03-07T08:32:29 stdout F       2. endpoint, credential:signature
    2025-03-07T08:32:29 stdout F       3. endpoint, credential:accountName, credential:accountKey
    2025-03-07T08:32:29 stdout F       4. connectionString
    2025-03-07T08:32:29 stdout F       5. endpoint
    

    Apphost Source:

    var builder = DistributedApplication.CreateBuilder(args);
    
    var storage = builder.AddAzureStorage("storage")
                         .RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent)) ;
    
    builder.AddAzureFunctionsProject<Projects.FunctionApp2>("function-csharp-app").
        WithHostStorage(storage).
        WithExternalHttpEndpoints();
    
    builder.Build().Run();
    

    Test Durable Function:

    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Azure.Functions.Worker.Http;
    using Microsoft.DurableTask;
    using Microsoft.DurableTask.Client;
    using Microsoft.Extensions.Logging;
    
    namespace FunctionApp2
    {
        public class Function(DurableTaskClient client, ILogger<Function> logger)
        {
            [Function(nameof(Function))]
            public  Task<List<string>> RunOrchestrator(
                [OrchestrationTrigger] TaskOrchestrationContext context)
            {
                logger.LogInformation("Orchestration Running.");
    
                return Task.FromResult<List<string>>(["Hello Tokyo!", "Hello Seattle!", "Hello London!"]);
            }
    
            [Function("Function_HttpStart")]
            public async Task<HttpResponseData> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
            {
                // Function input comes from the request content.
                string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
                    nameof(Function));
    
                logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
    
                // Returns an HTTP 202 response with an instance management payload.
                // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
                return await client.CreateCheckStatusResponseAsync(req, instanceId);
               
            }
        }
    }
    

    Program.cs for host of durable function:

    using Microsoft.Azure.Functions.Worker.Builder;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    using Microsoft.DurableTask.Client;
    
    var builder = FunctionsApplication.CreateBuilder(args);
    
    builder.AddServiceDefaults();
    
    // Needed to get the durable client 
    builder.Services.AddDurableTaskClient(b => b.UseGrpc());
    
    builder.Build().Run();
    
    

    Project file for durable function host:

    <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="2.0.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.2.2" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Tables" Version="1.4.2" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.1" />
      </ItemGroup>
      <ItemGroup>
        <ProjectReference Include="..\AspireApp1.ServiceDefaults\AspireApp1.ServiceDefaults.csproj" />
      </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>
    

    host.json:

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          },
          "enableLiveMetricsFilters": true
        }
      }
    }
    

    local.settings.json:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "",
            "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
        }
    }
    

    Now I don't know how relevant this is, but when you used setup durable functions to work with containers, you have to use a specific base Microsoft docker container (see https://mcr.microsoft.com/catalog?search=functions) . Also, you specified details about where the storage for the durable functions within the host.json. Its currently not clear to me how much / little of this is required or relevant with getting Durable functions working with Aspire.

  11. mobackanandj commented on Mar 7, 2025

    @mobackanandj

    Error: 2025-03-07T08:32:29 stdout F fail: Host.Startup[515]
    2025-03-07T08:32:29 stdout F A host error has occurred during startup operation '450b8ff4-200b-4b66-a429-13b918f7267a'.
    2025-03-07T08:32:29 stdout F System.InvalidOperationException: Unable to find matching constructor while trying to create an instance of TableServiceClient.

    please invoke constructor properly. like below

    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Azure.Functions.Worker.Http;
    using Microsoft.DurableTask.Client;
    using Microsoft.DurableTask.Worker;
    using Microsoft.Extensions.Logging;

    public class Function
    {
    private readonly DurableTaskClient _client;
    private readonly ILogger _logger;

    public Function(DurableTaskClient client, ILogger<Function> logger)
    {
        _client = client;
        _logger = logger;
    }
    
    [Function(nameof(Function))]
    public Task<List<string>> RunOrchestrator([OrchestrationTrigger] TaskOrchestrationContext context)
    {
        _logger.LogInformation("Orchestration Running.");
    
        return Task.FromResult(new List<string> { "Hello Tokyo!", "Hello Seattle!", "Hello London!" });
    }
    
    [Function("Function_HttpStart")]
    public async Task<HttpResponseData> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
    {
        // Function input comes from the request content.
        string instanceId = await _client.ScheduleNewOrchestrationInstanceAsync(nameof(Function));
    
        _logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
    
        // Returns an HTTP 202 response with an instance management payload.
        // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
        return await _client.CreateCheckStatusResponseAsync(req, instanceId);
    }
    

    }

  12. VistianOpenSource commented on Mar 7, 2025

    @VistianOpenSource
    Author

    Error: 2025-03-07T08:32:29 stdout F fail: Host.Startup[515] 2025-03-07T08:32:29 stdout F A host error has occurred during startup operation '450b8ff4-200b-4b66-a429-13b918f7267a'. 2025-03-07T08:32:29 stdout F System.InvalidOperationException: Unable to find matching constructor while trying to create an instance of TableServiceClient.

    please invoke constructor properly. like below

    using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.DurableTask.Client; using Microsoft.DurableTask.Worker; using Microsoft.Extensions.Logging;

    public class Function { private readonly DurableTaskClient _client; private readonly ILogger _logger;

    public Function(DurableTaskClient client, ILogger<Function> logger)
    {
        _client = client;
        _logger = logger;
    }
    
    [Function(nameof(Function))]
    public Task<List<string>> RunOrchestrator([OrchestrationTrigger] TaskOrchestrationContext context)
    {
        _logger.LogInformation("Orchestration Running.");
    
        return Task.FromResult(new List<string> { "Hello Tokyo!", "Hello Seattle!", "Hello London!" });
    }
    
    [Function("Function_HttpStart")]
    public async Task<HttpResponseData> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
    {
        // Function input comes from the request content.
        string instanceId = await _client.ScheduleNewOrchestrationInstanceAsync(nameof(Function));
    
        _logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
    
        // Returns an HTTP 202 response with an instance management payload.
        // See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
        return await _client.CreateCheckStatusResponseAsync(req, instanceId);
    }
    

    }

    Whatever way round how you write the constructor, it doesn't matter. Locally it works fine, deployed, using Aspire, to a container on Azure, it doesn't.

    The error shown relates to the startup of the durables code where it is attempting to initialising storage. It hasn't even get to the point of being able to invoke the Function_HttpStart endpoint.

    To eliminate any environmental issues that may occur due to subsequent publish operations not working correctly, i've deleted the test environment I have on Azure and created a new one. Situation the same as already reported .

  13. davidfowl commented on Mar 9, 2025

    @davidfowl
    Collaborator

    Safia Abdalla (@captainsafia) fixed this recently #7961 and it might be related to the issues you are seeing around durable functions

  14. captainsafia commented on Mar 9, 2025

    @captainsafia
    Contributor

    Catching up on this thread. We don't currently have 100% support for Durable Functions in deployed scenarios.

    @captainsafia fixed this recently #7961 and it might be related to the issues you are seeing around durable functions

    mobackanandj For the specific issue that you re seeing, the PR referenced above should resolve it. Note that you will need to use a nightly version of the Aspire packages.

  15. VistianOpenSource commented on Mar 10, 2025

    @VistianOpenSource
    Author

    Catching up on this thread. We don't currently have 100% support for Durable Functions in deployed scenarios.

    @captainsafia fixed this recently #7961 and it might be related to the issues you are seeing around durable functions

    @mobackanandj For the specific issue that you re seeing, the PR referenced above should resolve it. Note that you will need to use a nightly version of the Aspire packages.

    Hi

    Well, I added the nuget source for the nightly builds, updated all referenced packages from this source, and deployed to Azure. It now functions correctly i.e. no errors upon launch, correctly discovers the durable functions, and invocation of durables works. Thanks!

    The updated packages in the host were

        <PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.0-preview.1.25159.2" />
        <PackageReference Include="Aspire.Hosting.Azure.Functions" Version="9.2.0-preview.1.25159.2" />
    
    

    More generally, in a typical setup with durable functions you'd provide certain configuration details using the host.json. Is that still the case, or has/is the configuration supposed to come from the host instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-integrationsazure

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions