The code generator produces a helper method that fails to compile when an endpoint's Run method accepts only HttpContext. This is because ASP.NET Core's MapPost returns different types based on the delegate's signature.
The Problem: In the generated partial class, the MapPost wrapper is defined as:
private RouteHandlerBuilder MapPost([StringSyntax("Route")] string pattern)
{
return _endpointRouteBuilder.MapPost(pattern, Run);
}
- Case A: If Run includes injected services (e.g., Run(IService service, HttpContext context)), the compiler treats it as a standard Delegate. MapPost returns RouteHandlerBuilder, and the code compiles.
- Case B: If Run matches the RequestDelegate signature (e.g., Run(HttpContext context)), MapPost returns IEndpointConventionBuilder. This causes a compilation error because IEndpointConventionBuilder cannot be implicitly converted to RouteHandlerBuilder.
Error Message: CS0266: Cannot implicitly convert type 'Microsoft.AspNetCore.Builder.IEndpointConventionBuilder' to 'Microsoft.AspNetCore.Builder.RouteHandlerBuilder'.
Suggested Fix: Update the code generator to use IEndpointConventionBuilder as the return type for the generated MapPost helper. This interface is the base for RouteHandlerBuilder and will work correctly for both RequestDelegate and standard Delegate overloads.
// Suggested change in generator output:
private IEndpointConventionBuilder MapPost(string pattern) => _endpointRouteBuilder.MapPost(pattern, Run);
The code generator produces a helper method that fails to compile when an endpoint's Run method accepts only HttpContext. This is because ASP.NET Core's MapPost returns different types based on the delegate's signature.
The Problem: In the generated partial class, the MapPost wrapper is defined as:
Error Message: CS0266: Cannot implicitly convert type 'Microsoft.AspNetCore.Builder.IEndpointConventionBuilder' to 'Microsoft.AspNetCore.Builder.RouteHandlerBuilder'.
Suggested Fix: Update the code generator to use IEndpointConventionBuilder as the return type for the generated MapPost helper. This interface is the base for RouteHandlerBuilder and will work correctly for both RequestDelegate and standard Delegate overloads.