Home

.net 6.0 - ControllerBase not working with Minimal Api

Hi,

I'm expecting the below code to show this result:

instead i'm getting:

The same code will work fine within a regular webapi project.
Only with linqpad, it appears dotnet isn't picking up the ControllerBase classes.


Code:

`

async Task Main()
{
    var builder = WebApplication.CreateBuilder();

    builder.Services.AddControllers();
    builder.Services.AddEndpointsApiExplorer();
    builder.Services.AddSwaggerGen();

    var app = builder.Build();

    app.UseSwagger();
    app.UseSwaggerUI();
    app.MapControllers();

    app.MapGet("test1", () => "ok");

    app.Run();
}

[ApiController, Route("test2")]
public class MyController : ControllerBase
{
    [HttpGet]
    public string Test2() => "ok";
}

`

Note: the issue is only with the minimal api builder i.e. WebApplication.CreateBuilder

Sign In or Register to comment.