Starting Azure Service Bus Trigger Function throws InvalidOperationException for "Host not yet started"

5

I have a v.2 Service Bus Trigger function which, when I attempt to start, throws the following exception:

System.InvalidOperationException
  HResult=0x80131509
  Message=The host has not yet started.
  Source=Microsoft.Azure.WebJobs.Host
  StackTrace:
   at Microsoft.Azure.WebJobs.JobHost.StopAsync() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 121
   at Microsoft.Azure.WebJobs.Hosting.JobHostService.StopAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Hosting\JobHostService.cs:line 32
   at Microsoft.Extensions.Hosting.Internal.Host.<StopAsync>d__10.MoveNext()

I've searched around but cannot find anyone with a similar issue (and fix). I'm running VS 15.8.7 with all extensions and packages updated.

Here's what my function looks like:

[FunctionName("ServiceBusListenerFunction")]
        public static void Run([ServiceBusTrigger("myTopic", "MySubscription", Connection = "MyConnection")]string mySbMsg, ILogger log)
        {
            log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
        }

And here's my local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "MyConnection": "UseDevelopmentStorage=true",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
  },
  "Host": {
    "LocalHttpPort": 7077
  }    
}

I also tried doing the following in launchSettings.json, but it didn't help:

{
  "profiles": {
    "MyProject": {
      "commandName": "Project",
      "executablePath": "C:\\Users\\[myUserName\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin\\func.dll",
      "commandLineArgs": "host start --port 7077"
    }
  }
}

I have Service Bus Explorer running and have created the above-named topic and subscription on it. The project in which the functions are located is built against .NET Standard 2.0.

Please let me know if you have any suggestions or need additional information.

EDIT: I grabbed the red exception text that appears briefly in the console window before it closes (which happens right before I get the above exception), and it reads:

Host initialized
A host error has occurred
System.Private.Uri: Value cannot be null
Parameter name: uriString
Stopping job host

Searching on this, I found this, but it doesn't seem as though I should have to change the attribute to get this working.

Thanks in advance for any help.

azure
azure-functions
azureservicebus
azure-servicebus-queues
asked on Stack Overflow Oct 23, 2018 by RobC • edited Oct 23, 2018 by Karishma Tiwari - MSFT

2 Answers

2

Problem is caused by this setting

"MyConnection": "UseDevelopmentStorage=true"

UseDevelopmentStorage=true represents Storage emulator connection string, for a Service Bus trigger, use Service Bus connection string(same one used in Service Bus Explorer or find it in Azure portal).

Some improvements:

In local.settings.json, LocalHttpPort somehow doesn't work in VS, you can remove it as commandLineArgs in launchSettings.json works as expected.

AzureWebJobsDashboard is not required now, so it can be deleted without special purpose.

In launchSettings.json, remove executablePath which is invalid as well. Usually we don't need this setting as VS use latest CLI by default.

answered on Stack Overflow Oct 24, 2018 by Jerry Liu • edited Oct 24, 2018 by Jerry Liu
2

One of the ways, I sorted the issue by removing the connection string from the [ServiceBusTrigger] and inserting it through local.settings.json.

in the function file.

 [ServiceBusTrigger("Your-Topics-Name", "SubscriptionName",Connection = "MyServiceBus")]

Inside the local.settings.json.

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsMyServiceBus": "your connection string",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}
  • note: connection string name start with the "AzureWebJobs" so you can put the remaining as the name.
answered on Stack Overflow May 21, 2019 by Arunagirirajah Nirooshan • edited Oct 22, 2020 by Liam

User contributions licensed under CC BY-SA 3.0