Running into an issue when trying to get my Azure Function V2 to run in a docker container. The project reads from an Azure Service Bus Topic. The error I get isn't descriptive and I'm not sure what value is actually null. When I run the project locally I have no issues but when I create a container for it I get this error.
Is it an environment variable that I'm not passing in or is it not reading from the appsettings.json correctly?
Environment variables
APPINSIGHTS_INSTRUMENTATIONKEY
AzureWebJobsStorage
AzureFunctionsWebHost__hostid
AzureWebJobsServiceBus
This is my function
public async void Run([ServiceBusTrigger(TopicName, SubscriptionName, Connection = "AzureWebJobsServiceBus")] Message message, string lockToken, MessageReceiver messageReceiver, ILogger log)
This is my Dockerfile
FROM microsoft/dotnet:2.2-sdk AS installer-env
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish Project/Project.csproj --output /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
COPY --from=installer-env ["/src/dotnet-function-app/Project/Microsoft.Azure.WebJobs.Script.WebHost.runtimeconfig.json", "/azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost.runtimeconfig.json"]
ENTRYPOINT ["/azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost", "--runtimeconfig", "/azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost.runtimeconfig.json"]
This is the error
fail: Host.Startup[515]
A host error has occurred during startup operation '6143cd8a-c857-4cfc-b52a-930e0de0d836'.
System.ArgumentNullException: Value cannot be null.
Parameter name: uriString
at System.Uri..ctor(String uriString)
at Microsoft.Azure.ServiceBus.ServiceBusConnection.InitializeConnection(ServiceBusConnectionStringBuilder builder)
at Microsoft.Azure.ServiceBus.Core.MessageReceiver..ctor(String connectionString, String entityPath, ReceiveMode receiveMode, RetryPolicy retryPolicy, Int32 prefetchCount)
at Microsoft.Azure.WebJobs.ServiceBus.MessagingProvider.GetOrAddMessageReceiver(String entityPath, String connectionString)
at Microsoft.Azure.WebJobs.ServiceBus.MessagingProvider.CreateMessageProcessor(String entityPath, String connectionString)
at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener..ctor(String entityPath, Boolean isSessionsEnabled, ServiceBusTriggerExecutor triggerExecutor, ServiceBusOptions config, ServiceBusAccount serviceBusAccount, MessagingProvider messagingProvider)
at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListenerFactory.CreateAsync(CancellationToken cancellationToken)
at Microsoft.Azure.WebJobs.ServiceBus.Triggers.ServiceBusTriggerBinding.CreateListenerAsync(ListenerFactoryContext context)
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.ListenerFactory.CreateAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 426
at Microsoft.Azure.WebJobs.Host.Listeners.HostListenerFactory.CreateAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\HostListenerFactory.cs:line 67
at Microsoft.Azure.WebJobs.Host.Listeners.ListenerFactoryListener.StartAsyncCore(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\ListenerFactoryListener.cs:line 45
at Microsoft.Azure.WebJobs.Host.Listeners.ShutdownListener.StartAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\ShutdownListener.cs:line 29
at Microsoft.Azure.WebJobs.JobHost.StartAsyncCore(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 103
at Microsoft.Azure.WebJobs.Script.ScriptHost.StartAsyncCore(CancellationToken cancellationToken) in /src/azure-functions-host/src/WebJobs.Script/Host/ScriptHost.cs:line 249
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Azure.WebJobs.Script.WebHost.WebJobsScriptHostService.UnsynchronizedStartHostAsync(ScriptHostStartupOperation activeOperation, Int32 attemptCount, JobHostStartupMode startupMode) in /src/azure-functions-host/src/WebJobs.Script.WebHost/WebJobsScriptHostService.cs:line 237
info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
Stopping JobHost
UPDATE:
Ended up using the wrong connection string.
From the call stack in your post, I think error is for the connection string not set for the Service Bus Trigger.
Did you set the environment variable with the connection string appropriately?
From the docs,
[FunctionName("ServiceBusQueueTriggerCSharp")]
public static void Run(
[ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")]
string myQueueItem,
Int32 deliveryCount,
DateTime enqueuedTimeUtc,
string messageId,
ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
log.LogInformation($"EnqueuedTimeUtc={enqueuedTimeUtc}");
log.LogInformation($"DeliveryCount={deliveryCount}");
log.LogInformation($"MessageId={messageId}");
}
If you have the above code, then you'd want to set an environment variable ServiceBusConnection
equal to the connection string.