title: Azure Function V2 Value cannot be null
body: <p>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. </p>
  
  <p>Is it an environment variable that I'm not passing in or is it not reading from the appsettings.json correctly?</p>
  
  <p>Environment variables</p>
  
  <pre><code>APPINSIGHTS_INSTRUMENTATIONKEY
  AzureWebJobsStorage
  AzureFunctionsWebHost__hostid
  AzureWebJobsServiceBus
  </code></pre>
  
  <p>This is my function</p>
  
  <pre><code>public async void Run([ServiceBusTrigger(TopicName, SubscriptionName, Connection = "AzureWebJobsServiceBus")] Message message, string lockToken, MessageReceiver messageReceiver, ILogger log)
  </code></pre>
  
  <p>This is my Dockerfile</p>
  
  <pre><code>FROM microsoft/dotnet:2.2-sdk AS installer-env
  
  COPY . /src/dotnet-function-app
  
  RUN cd /src/dotnet-function-app &amp;&amp; \
      mkdir -p /home/site/wwwroot &amp;&amp; \
      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"]
  </code></pre>
  
  <p>This is the error</p>
  
  <pre><code>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
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>Ended up using the wrong connection string.</p>