title: How to manually handle message completion in C# azure function with azure service bus 5.0.0
body: <p>I'm writing an Azure Function to get the messages in an Azure Service Bus.
  I want to handle any exceptions manually (<code>&quot;autoCompleteMessages&quot;: false</code>)
  Can't figure how to send the complete or abandon back to the service queue.</p>
  <p><em><strong>Tried Option 1:</strong></em></p>
  <pre><code>[FunctionName(&quot;SBQ_F1_VC&quot;)]
  public static async Task Run([ServiceBusTrigger(&quot;sbqfn1&quot;, Connection = &quot;BrnlTest1_SERVICEBUS&quot;)]
      ServiceBusReceivedMessage msg, ILogger log)
  {
  //.....
  
      if(!Int32.TryParse(msg.ApplicationProperties.GetValueOrDefault(&quot;vid&quot;).ToString(), out vid))
      {   await using ServiceBusClient client = new ServiceBusClient(Environment.GetEnvironmentVariable(&quot;BrnlTest1_SERVICEBUS&quot;));
          ServiceBusReceiver msgRcvr = client.CreateReceiver(Environment.GetEnvironmentVariable(&quot;queueName&quot;), new ServiceBusReceiverOptions()); 
          //await msgRcvr.RenewMessageLockAsync(msg);
          await msgRcvr.AbandonMessageAsync(msg);  //vid = 0;
      }
  
  //.....
  }
  </code></pre>
  <p><em><strong>Errors Option 1</strong></em></p>
  <pre><code>System.Private.CoreLib: Exception while executing function: SBQ_F1_VC. Azure.Messaging.ServiceBus: 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. (MessageLockLost).
  </code></pre>
  <p><em><strong>Tried Option 2:</strong></em></p>
  <pre><code>[FunctionName(&quot;SBQ_F1_VC&quot;)]
          public static async Task Run([ServiceBusTrigger(&quot;sbqfn1&quot;, Connection = &quot;BrnlTest1_SERVICEBUS&quot;)]
           ServiceBusReceivedMessage[] msgs,
           ServiceBusMessageActions msgActions)
          {
          //.....
          await msgActions.DeadLetterMessageAsync(msg);
          
          }
  </code></pre>
  <p><em><strong>Errors Option 2:</strong></em></p>
  <pre><code>Microsoft.Azure.WebJobs.Host: Error indexing method 'SBQ_F1_VC'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'msgActions' to type ServiceBusMessageActions. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
  </code></pre>
  <p><strong>Notes:</strong></p>
  <ul>
  <li>Service Bus is 5.0.0 so I have to use <code>Azure.Messaging.ServiceBus</code> namespace
  <ul>
  <li>This implies the message object is <code>ServiceBusReceivedMessage</code></li>
  </ul>
  </li>
  </ul>
  <hr />
  <h2 id="what-worked-based-on-jesses-and-joshs-answers"><em><strong>What worked (based on Jesse's and Josh's answers)</strong></em></h2>
  <p>The Parameter Name for <code>ServiceBusMessageActions</code> <em><strong>MUST</strong></em> be <code>messageActions</code>.<br/>
  Changing this name is not tolerated for some reason...</p>
  <pre><code>public static async Task Run(
          [ServiceBusTrigger(&quot;sbqfn1&quot;, Connection = &quot;BrnlTest1_SERVICEBUS&quot;)]
          ServiceBusReceivedMessage[] msgs,
          ServiceBusMessageActions messageActions)
          {
  </code></pre>