I am using ASP.NET Core Minimal APIs with .NET 8.
I have an application that adds some endpoints.
One of these endpoints is not valid, but the app starts normaly:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5031
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/fine/{x}", (int x) => "I am {x}");
// Invalid, cause binding to the type 'NotBindable' of y is not possible
app.MapGet("/bad/{y}", (NotBindable y) => $"I am {y.Value}");
app.Run();
public class NotBindable
{
public string Value { get; set; }
}
When I request any of the endpoints, whether a valid one or an incorrect one, I get an exception (as expected)
System.InvalidOperationException: Body was inferred but the method does not allow inferred body parameters.
Below is the list of parameters that we found:
Parameter | Source
---------------------------------------------------------------------------------
y | Body (Inferred)
Did you mean to register the "Body (Inferred)" parameter(s) as a Service or apply the [FromServices] or [FromBody] attribute?
I want to get this error when starting the application and not when accessing the endpoints for the first time. Does anyone have an idea how I can achieve this behavior?
thanks mMilk