0

I'm using .NET 5.0, Azure runtime 3.

I have an Azure function that triggers based on a service bus. The function declaration looks like:

[FixedDelayRetry(0, "00:00:00")]
[Function("MyFunkyFunc")]
public async Task Run(
    [ServiceBusTrigger("myqueuenname", Connection = "MyQueueConnection")] string myQueueItem,
    FunctionContext context)
{
    ...
}

From Visual Studio when I debug I receive the following message(s):

Azure Functions Core Tools
Core Tools Version:       3.0.3904 Commit hash: c345f7140a8f968c5dbc621f8a8374d8e3234206(64-bit)
Function Runtime Version: 3.3.1.0

[2021-11-29T20:42:11.704Z] A host error has occurred during startup operation '8cc138c0-e49a-4acb-a10e-60648d4548ad'.
[2021-11-29T20:42:11.705Z] Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'MyQueueConnection' is missing or empty.
Value cannot be null. (Parameter 'provider')
Press any to continue....

The "a host error" and "connect string missing" messages repeat over and over. If I press enter the run ends.

HOWEVER... my Program.Main method is not invoked. It's in there where I initialize DI etc and do a "builder.AddUserSecrets();" so my connection string will be loaded from user secrets.

My Program.Main is not invoked prior to these errors. Which seems backwards, very backwards. My function has a few dependencies that are provided by DI so part of the runtime is trying to connect to the service bus before it could possible even create an instance of the receiving function.

Does the azure function debugging thingy just not work with Program.Main?

How can I tell the azure function debugging thingy to use UserSecrets?

Thanks!!

user2845090
  • 147
  • 3
  • 14
  • If your queue trigger in function app has to dynamically resolve queue name, without depending on App setting or variable from local.settings.json, then you need to use `binding at runtime`, as explained [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library?tabs=v2%2Ccmd#binding-at-runtime) – Anand Sowmithiran Nov 30 '21 at 12:46
  • As it is, your code has `[ServiceBusTrigger("myqueuenname", Connection = "MyQueueConnection")`, so the function app runtime will look for MyQueueConnection in your `local.settings.json` file. If you like the queue name to be dynamic, you can use % sign before and after, like so , %myqueue%, and then define `myqueue` in that json file for local dev. While running on Azure, these can be created as App Settings for your function app. If you want it only to be derived by code at run time, refer my above comment for `binding at runtime`. – Anand Sowmithiran Nov 30 '21 at 13:21
  • I'm not concerned about the queue name... that will be constant. It's the connection string to the queue itself that needs to be treated as a secret, just the development connection string (production is fine). – user2845090 Nov 30 '21 at 15:26
  • same approach applies for connection string attribute, you could use the Binder class and read it from user secrets so that you don't have to publicly place it in the settings json file. – Anand Sowmithiran Nov 30 '21 at 15:51

0 Answers0