microsoft / microsoft/aspire

Durable Functions work correctly locally, but not when deployed?

Open
#7,828 14 comments 0 reactions 0 assignees View on GitHub
area-integrations azure
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] 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> RunOrchestrator(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
ILogger logger = context.CreateReplaySafeLogger(nameof(Function));
logger.LogInformation("Saying hello.");
var outputs = new List();

// Replace name and input with values relevant for your Durable Functions Activity
outputs.Add(await context.CallActivityAsync(nameof(SayHello), "Tokyo"));
outputs.Add(await context.CallActivityAsync(nameof(SayHello), "Seattle"));
outputs.Add(await context.CallActivityAsync(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 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.