1
votes

I created an azure function with service bus trigger, when I try to run the function I get this error:

[2021-01-07T12:32:43.565Z] A host error has occurred during startup operation '4f45a03c-9302-43c6-8c54-e6555bc0f562'.
[2021-01-07T12:32:43.566Z] System.Private.Uri: Value cannot be null. (Parameter 'uriString').

I have my local.settings.json file set up for development storage

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

and I have the connection string in the function using AzureWebJobsStorage

public static class ProcessAS2ExchangeInboundExceptions
    {
        [FunctionName("ProcessAS2ExchangeInboundExceptions")]
        public static void Run(
            [ServiceBusTrigger("as2-exchange-inbound-topic", "exceptions", Connection = "AzureWebJobsStorage")] string myQueueItem,
            ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

        }

    }

I am not sure what the issue is. Any help would be appreciated.

1

1 Answers

2
votes

As per your config, AzureWebJobsStorage is representing a connection string the Azure Storage instead of Azure Service Bus. So either you should define a new config to connect to Azure Service Bus instance with topic and subscription name (make sure to have a instance of Azure Service Bus is spinned-up in Azure) or use QueueTrigger with queue name to work with Azure Storage.

Updated below code to represent the QueueTrigger

public static class ProcessAS2ExchangeInboundExceptions
{
    [FunctionName("ProcessAS2ExchangeInboundExceptions")]
    public static void Run(
        [QueueTrigger("as2-exchange-inbound-queue", Connection = "AzureWebJobsStorage")] string myQueueItem,
        ILogger log)
    {
        log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

    }

}

Queue Trigger - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=csharp

Azure Service Bus Trigger - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp