Repository navigation
Description
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
davidfowl commentedon Feb 28, 2025
Where is the apphost code?
VistianOpenSource commentedon Feb 28, 2025
Apologies
davidfowl commentedon Feb 28, 2025
I would remove these customizations and stick to the happy path.
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.
VistianOpenSource commentedon Feb 28, 2025
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:
The main file of the azure function project looks like this:
Deployed, to azure, console log for the azure function project looks like:
The host.json in the Azure functions project, only contains:
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.
mobackanandj commentedon Mar 4, 2025
Hi Team,
Any update on this issue ? as issue is Durable Functions work correctly locally, but not when deployed?
mobackanandj commentedon Mar 6, 2025
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:
Update in Program.cs:
davidfowl commentedon Mar 7, 2025
Did you get it working?
mobackanandj commentedon Mar 7, 2025
Yes! After implementing these changes, the DurableTaskClient is now successfully invoking _client.ScheduleNewOrchestrationInstanceAsync. Give it a try!
VistianOpenSource commentedon Mar 7, 2025
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:
Apphost Source:
Test Durable Function:
Program.cs for host of durable function:
Project file for durable function host:
host.json:
local.settings.json:
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.
mobackanandj commentedon Mar 7, 2025
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;
}
VistianOpenSource commentedon Mar 7, 2025
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 .
davidfowl commentedon Mar 9, 2025
Safia Abdalla (@captainsafia) fixed this recently #7961 and it might be related to the issues you are seeing around durable functions
captainsafia commentedon Mar 9, 2025
Catching up on this thread. We don't currently have 100% support for Durable Functions in deployed scenarios.
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.
VistianOpenSource commentedon Mar 10, 2025
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
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?