title: How to return OkObjectResult and BadObjectResult - C# Azure Function
body: <p>I am getting the following error &quot;Can not implicitly convert type &quot;Microsoft.AspNetCore.OkObjectResult&quot; to &quot;Microsoft.Omex.Bulk.Accessibility.Logging.AccessibilityErrorOutput&quot;when I try to execute the following line:</p>
  <p>Microsoft.Omex.Bulk.Accessibility.Logging.AccessibilityErrorOutput, is another class in the project. But it is not being used in this class, so what am I doing wrong here?</p>
  <p>I want to return HTTP results when the function is successful or not successfully executed.</p>
  <pre><code>        filePath ?? return new OkObjectResult(&quot;Accessibility Checker function executed successfully&quot;) : return new BadRequestObjectResult(&quot;Function did not execute successfully&quot;);
  </code></pre>
  <p>The full code of the Azure Function API:</p>
  <pre><code>namespace Microsoft.Omex.Bulk.Accessibility.Checker;
  using System.IO;
  using System.Net;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Http;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Azure.WebJobs;
  using Microsoft.Azure.WebJobs.Extensions.Http;
  using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
  using Microsoft.Extensions.Logging;
  using Microsoft.Omex.Bulk.Accessibility.Logging;
  using Microsoft.OpenApi.Models;
  using Newtonsoft.Json;
  
  /// &lt;summmary&gt;
  /// Azure function class to manage functional processing of Word document, Excel spreadsheet,
  /// Powerpoint presentation to detect acccessibility issues.
  /// &lt;/summary&gt;
  public class AccCheckerForOpenXML
  {
      private readonly ILogger&lt;AccCheckerForOpenXML&gt; logger;
      public AccCheckerForOpenXML(ILogger&lt;AccCheckerForOpenXML&gt; log) =&gt; this.logger = log;
      /// &lt;summary&gt;
      /// Function that receives a httptrigger and then starts processing documents the Office Open XML files.
      /// &lt;/summary&gt;
      
      [FunctionName(&quot;AccCheckerForOpenXML&quot;)]
      [OpenApiOperation(operationId: &quot;Run&quot;, tags: new[] { &quot;docName&quot; })]
      [OpenApiParameter(name: &quot;name&quot;, In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = &quot;The **Name** parameter&quot;)]
      [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: &quot;text/plain&quot;, bodyType: typeof(string), Description = &quot;The OK response&quot;)]
      public async Task&lt;AccessibilityErrorOutput&gt; Run(
              [HttpTrigger(AuthorizationLevel.Anonymous, &quot;get&quot;, &quot;post&quot;, Route = null)] HttpRequest req)
      {
          this.logger.LogInformation(&quot;AccCheckerForDocx: Run method:HTTP trigger --  function processed a request.&quot;); // 
          string filePath = req.Query[&quot;name&quot;]; // In the query will be a name
          var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
          dynamic data = JsonConvert.DeserializeObject(requestBody); // If not the name will be in JSON
          filePath ??= data?.name;
          filePath ?? return new OkObjectResult(&quot;Accessibility Checker function executed successfully&quot;) : return new BadRequestObjectResult(&quot;Function did not execute successfully&quot;);
      }
  }
  </code></pre>