Reputation: 125
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.
Upvotes: 1
Views: 11026
Reputation: 1006
I was getting the same error as the PO, the issue actually is because of the following situation, assuming that you have the basic implementation as such:
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("myqueue")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message:
{myQueueItem}");
}
By default the ConnectionString used by the ServiceBusTrigger attribute is called "AzureWebJobsServiceBus" and this is not set by default within your "local.settings.json" or your "settings.json" file.
So to get rid of this problem you either have to set the default value of it by adding to your "local.settings.json" file the following node/value:
"Values": {
"AzureWebJobsStorage": "your connection string for your storage account",
"AzureWebJobsServiceBus": "Your connection string for your service bus which you can get through azure portal"
}
If you want to have different name for this property "AzureWebJobsServiceBus" then you must specify the name in the "ServiceBusTrigger" parameter, as such:
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("myqueue", Connection = "MyServiceBusConnectionStringName")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message:
{myQueueItem}");
}
And then change your "local.settings.json" to:
"Values": {
"AzureWebJobsStorage": "your connection string for your storage account",
"MyServiceBusConnectionStringName": "Your connection string for your service bus which you can get through azure portal"
}
These nuances are quite important for people that are just beginning with Azure Functions.
Upvotes: 1
Reputation: 508
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.
Upvotes: 4
Reputation: 121649
From the Microsoft documentation:
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-exceptions
ArgumentException, ArgumentNullException, ArgumentOutOfRangeException:
One or more arguments supplied to the method are invalid.
The URI supplied to NamespaceManager orCreate contains path segment(s).
The URI scheme supplied to NamespaceManager or Create is invalid.
The property value is larger than 32 KB. Check the calling code and make sure the arguments are correct.
In other words, step through your code (if possible) in either/both of these methods and ensure there's a valid "uriString".
Upvotes: 1