-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-rdg
Milestone
Description
Given the code:
public static void TestGenericParam<TUser>(IEndpointRouteBuilder app) where TUser : class
{
app.MapPost("/test-param", ([FromServices] UserManager<TUser> userManager) => { });
}
public static void TestGenericResponse<TUser>(IEndpointRouteBuilder app) where TUser : new()
{
app.MapPost("/test-return", () => new TUser());
}RDG will generate code that fails to compile because TUser is undefined. As a short-term mitigation, we can skip generating MapPost and similar methods when we see an open generic parameter in the delegate signature. Long term, we can look at flowing the generic parameters through the Map methods we generate which can then hopefully be inferred.
GeneratedRouteBuilderExtensions.g.cs(73,85): error CS0246: The type or namespace name 'TUser' could not be found (are you missing a using directive or an assembly reference?)
GeneratedRouteBuilderExtensions.g.cs(88,33): error CS0246: The type or namespace name 'TUser' could not be found (are you missing a using directive or an assembly reference?)
internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost(
this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints,
[global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern,
global::System.Action<global::Microsoft.AspNetCore.Identity.UserManager<TUser>> handler, // <---- Error!
[global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "",
[global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0)
{
// ...
handler(ic.GetArgument<global::Microsoft.AspNetCore.Identity.UserManager<TUser>>(0)!);
// ...
var userManager_local = httpContext.RequestServices.GetRequiredService<Microsoft.AspNetCore.Identity.UserManager<TUser>>();
// ...
var handler = (Func<TUser>)del;
// ...
var jsonTypeInfo = (JsonTypeInfo<TUser>)serializerOptions.GetTypeInfo(typeof(TUser));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-rdg