2
votes

Sorry for the long post I just wanted to provide all the information I could and address questions before they come up.

Working on converting an Azure Function v1 .NET Framework 4.6.1 to a DotNetStandard 2.0 for the Dependency Injection extension. At runtime I get an exception in the Console that reads an error that the connection string is missing but it's in the local.settings.json as it was in v1. According to the documentation it should default to the AzureWebJobsServiceBus value in the local.settings.json file and the ApplicationSettings on Azure.

A host error has occurred

Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsServiceBus' is missing or empty.

I get a runtime exception immediately after that posts in the Console in JobHost.cs that "The host has not yet started."

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(CancellationToken cancellationToken)

Continuing through that exception gives me the next one "Container is disposed and should not be used: Container is disposed. You may include Dispose stack-trace into the message via: container.With(rules => rules.WithCaptureContainerDisposeStackTrace())"

at DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs:line 8991 at DryIoc.Container.ThrowIfContainerDisposed() in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs:line 411 at DryIoc.Container.ResolveAndCacheDefaultFactoryDelegate(Type serviceType, IfUnresolved ifUnresolved) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs:line 200 at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType, IfUnresolved ifUnresolved) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs:line 195 at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.JobHostServiceProvider.GetService(Type serviceType, IfUnresolved ifUnresolved) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\JobHostServiceProvider.cs:line 101 at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.JobHostServiceProvider.GetRequiredService(Type serviceType) in C:\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\DependencyInjection\JobHostServiceProvider.cs:line 84 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Azure.Functions.Cli.Actions.HostActions.StartHostAction.RunAsync() in C:\azure-functions-cli\src\Azure.Functions.Cli\Actions\HostActions\StartHostAction.cs:line 241

local.settings.json (among many values):

  ...,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "AzureWebJobsServiceBus": "Endpoint=sb://[my_name].servicebus.windows.net/;SharedAccessKeyName=LocalManage;SharedAccessKey=[my_key]",
    ...

My csproj file reads:

  <TargetFramework>netstandard2.0</TargetFramework>
  <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

I am working in Visual Studio 2017 Version 15.9.9

Azure Functions and Web Job Tools is 15.10.2046.0

Edit:

Doesn't seem limited to converting from v1 to v2

Recreation Steps

  1. Using Visual Studio 2017 go to File -> New -> Project -> Azure Functions -> Ok
  2. Choose Azure Functions v2 (.NET Core)
  3. Choose Empty
  4. Right click Project -> Add ->New Azure Function
  5. Select Service Bus Queue Trigger
  6. Go to local.settings.json and add a ServiceBusConnectionString
  7. Start Debugging and you'll get the exception above.
4
Just having this exact same problem. Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsServiceBus' is missing or empty. when it's right there in my settings. Are you behind a proxy or firewall? I've found that I cannot run service bus functions locally due to our corporate firewall, and there's no option to fallback on HTTP.Joe
There is no issue with a corporate firewall or proxy behind v1. When reverting back to v1 the ServiceBus connection string works fine. Did they change network protocols when it starts up to test the connection or something? I didn't see that in any documentation though.Justin Neff

4 Answers

1
votes

You have to add the Key Name from the settings file in order to get it to work now. See this GitHub issue.

[ServiceBusTrigger("mytopic",` "mysubscription", Connection = "ConnectionStringSettingName")]

Then in your local.settings.json

  ...,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "ConnectionStringSettingName": "Endpoint=sb://[my_name].servicebus.windows.net/;SharedAccessKeyName=LocalManage;SharedAccessKey=[my_key]",
...
0
votes

I've seen this very same issue when my local.settings.json file was malformed. Revert just your settings back to when everything was working, and you should be good.

0
votes

I have seen this issue when using a binding with mass transit with Azure WebJobs Extensions.ServiceBus 3.0.6.

For some reason it doesn't respect the named connection string so instead i had to use the DefaultConnectionStringName as apart of the extension.

In the Project you can see that it is consumed "ConnectionStrings:ServiceBus"

Therefore i updated the configuration have both, the custom "ServiceBusEndpoint" that you configure in the trigger and the DefaultConnectionStringName.

{
"IsEncrypted": false,
"Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "ServiceBusEndpoint": "Endpoint=sb://[my_name].servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=[KEYHERE]",
},
 "ConnectionStrings": {
    "ServiceBus": "Endpoint=sb://[my_name].servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=[KEYHERE]",
 }
}

This is not an Ideal solution, but its one work around available.

0
votes

I got this error not when trying to convert from v1 to v2, but just creating a new Azure Function Project with a Service Bus Trigger (v3 .netcore):

Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsServiceBus' is missing or empty

No adjust in host.json helped me. So I got into Azure Portal and did:

  1. Go to Azure Function App Configuration
  2. Click New Application Setting
  3. In the field "Name" put: AzureWebJobsServiceBus
  4. In the field "Value" put: Endpoint=sb://???.servicebus.windows.net/;SharedAccessKeyName=???;SharedAccessKey=???

My trigger code is (without Connection parameter):

[FunctionName("MyFunctionName")]
public static void Run([ServiceBusTrigger("myqueuename")] string queueItem, ILogger log)
{ ... }

My host.json file is:

{
    "version": "2.0",
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsServiceBus": "Endpoint=sb://???.servicebus.windows.net/;SharedAccessKeyName=???;SharedAccessKey=???"
    }
}