Azure function Isolated Process Model

Buyani Mhlongo 0 Reputation points
2025-03-14T13:10:09.8066667+00:00

I am using Azure Function Isolated process model .Net 8.0 I want to use Swagger UI as a result I installed Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Core.Attributes However tis does not work using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes work Why is this am I missing something?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. RithwikBojja 3,055 Reputation points Microsoft External Staff Moderator
    2025-03-19T05:27:34.7633333+00:00

    Hi @Buyani Mhlongo,

    To Use Swagger in . Net 8 Isolated you have inject ConfigureOpenApi in Program.cs also as below:

    
    using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions;
    
    using Microsoft.Extensions.Hosting;
    
    var rith = new HostBuilder()
    
            .ConfigureServices((context, services) =>
    
            {
    
            })
    
            .ConfigureFunctionsWebApplication(app =>
    
            {
    
            })
    
            .ConfigureOpenApi()
    
            .Build();
    
    rith.Run();
    
    

    Now, in Function1.cs, one needs to declare all the function definitions as below:

    
    using Microsoft.AspNetCore.Http;
    
    using Microsoft.AspNetCore.Mvc;
    
    using Microsoft.Azure.Functions.Worker;
    
    using Microsoft.Extensions.Logging;
    
    using Microsoft.OpenApi.Models;
    
    using System.Net;
    
    using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
    
    using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
    
    using Newtonsoft.Json;
    
    using System.Web.Helpers;
    
    using System.Text.Json;
    
    namespace FunctionApp4
    
    {
    
        public class Function1
    
        {
    
            private readonly ILogger<Function1> _logger;
    
            public Function1(ILogger<Function1> logger)
    
            {
    
                _logger = logger;
    
            }
    
            [Function("Function1")]
    
            [OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
    
            [OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
    
            [OpenApiParameter(name: "JSON", In = ParameterLocation.Query, Required = true, Type = typeof(Json), Description = "Hello Rithwk Bojja, The **JSON** parameter")]
    
            [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
    
            public async Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
    
            {
    
                _logger.LogInformation("Hello Rithwik Bojja");            
    
                return new OkObjectResult("Hello");
    
            }
    
        }
    
    }
    
    

    Csproj:

    
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
    
        <TargetFramework>net8.0</TargetFramework>
    
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    
        <OutputType>Exe</OutputType>
    
        <ImplicitUsings>enable</ImplicitUsings>
    
        <Nullable>enable</Nullable>
    
      </PropertyGroup>
    
      <ItemGroup>
    
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
    
        <PackageReference Include="Microsoft.AspNet.WebPages" Version="3.3.0" />
    
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" />
    
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
    
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi.Core" Version="1.5.1" />
    
        <PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
    
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    
      </ItemGroup>
    
      <ItemGroup>
    
        <None Update="host.json">
    
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    
        </None>
    
        <None Update="local.settings.json">
    
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    
        </None>
    
      </ItemGroup>
    
      <ItemGroup>
    
        <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
    
      </ItemGroup>
    
    </Project>
    
    

    local.settings.json:

    
    {
    
        "IsEncrypted": false,
    
        "Values": {
    
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    
            "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    
        }
    
    }
    
    

    Output:

    enter image description here

    enter image description here

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.