title: How to set Autocomplete in MessageHandlerOptions in Azure Service Bus Options (using Net Core 3.1)
body: <p>I am writing a webjob using .NET Core 3.1 and my trigger looks like:</p>
  <pre><code>public async Task ProcessQueueMessage([ServiceBusTrigger(&quot;%ServiceBusProviderConfig:TopicName%&quot;, &quot;%ServiceBusProviderConfig:TopicSubscriptionName%&quot;, Connection = &quot;ServiceBusConnectionString&quot;)] Message message, MessageReceiver messageReceiver, TraceWriter log, TextWriter textWriter)
  </code></pre>
  <p>I am processing the message and calling complete / dead lettering as per the requirement in the following manner:</p>
  <pre><code>await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
  await messageReceiver.DeadLetterAsync(message.SystemProperties.LockToken);
  </code></pre>
  <p>However, this is throwing the error:
  <code> The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance.</code></p>
  <p>I understand that I need to somehow set the Autocomplete in MessageHandlerOptions to false for the webjob to not automatically complete it and remove from the queue.</p>
  <p>But I am having difficulty setting this value. I tried:</p>
  <ol>
  <li><p>setting this in the appsettings.json file as follows:</p>
  <p>&quot;extensions&quot;: {
  &quot;serviceBus&quot;: {
  &quot;messageHandlerOptions&quot;: {
  &quot;maxConcurrentCalls&quot;: 16,
  &quot;autoComplete&quot;: false
  }
  }
  }</p>
  </li>
  </ol>
  <p>But on running, it is not picking the settings from this file. I am not sure why, how can I make the settings be read from local config file?</p>
  <ol start="2">
  <li><p>I also tried creating an object for MessageHandlerOptions but it the signature is missing a required param which makes it impossible to do this. Eg:</p>
  <pre><code> var messageHandlerOptions = new MessageHandlerOptions(ExceptionHandler)
   {
       AutoComplete = false,
       MaxAutoRenewDuration = new TimeSpan(0, 5, 0), // 5 minutes
       MaxConcurrentCalls = 1,
   };
  
  messageReceiver.RegisterMessageHandler(MessageProcessor, messageHandlerOptions);
  </code></pre>
  <p>static async Task MessageProcessor(Message message, CancellationToken token)
  {
  await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
  }</p>
  </li>
  </ol>
  <p>I am unable to access <code>messageReceiver</code> within <code>MessageProcessor</code> and thats why this is not possible too.</p>
  <p>Can anyone please suggest how I can set ServiceBusOptions in a config file to be read at runtime?</p>
  <p>FYI, I am using the following packages:</p>
  <pre><code>1. Microsoft.Azure.ServiceBus Version=&quot;4.1.3&quot;
  2. Microsoft.Azure.WebJobs.Extensions Version=&quot;3.0.0&quot;
  3. Microsoft.Azure.WebJobs.Extensions.ServiceBus Version=&quot;3.0.0&quot;
  4. Microsoft.Azure.WebJobs.Extensions.Storage Version=&quot;4.0.2&quot;
  5. Microsoft.Azure.WebJobs.Logging.ApplicationInsights Version=&quot;3.0.14&quot;
  </code></pre>