Home

Same mini asp.net core code in LINQPad unable to get responsed but good in Visual Studio

Let's say following code:

var builder = WebApplication.CreateBuilder();
builder.Services.AddControllers();
var app = builder.Build();
app.UseRouting();
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();

public class HomeController : Controller
{
    public DateTime Index()
    {
        return DateTime.Now;
    }
}

Is unable to get responsed for path: https://localhost:5001/home:

But good in Visual Studio 2022:

Comments

  • It works when You manually add current assembly for ASP.NET to scan

    var builder = WebApplication.CreateBuilder();
    builder.Services.AddControllers().AddApplicationPart(typeof(HomeController).Assembly);
    var app = builder.Build();
    app.UseRouting();
    app.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
    app.Run();
    
    public class HomeController : Controller
    {
        public DateTime Index()
        {
            return DateTime.Now;
        }
    }
    
Sign In or Register to comment.