Is there an existing issue for this?
Describe the bug
I have an internal application that has a user interface where various properties of a configuration object can be changed independently. To reduce duplication for this operations, various HTTP PATCH endpoints with different URLs call through a generic method that maps the endpoint based on a code pattern.
The method is essentially this where boilerplate wraps the invocation of a delegate with a generic parameter:
private static RouteHandlerBuilder MapRepositoryUpdate<T>(
this IEndpointRouteBuilder endpoints,
string pattern,
Func<IConfigurationRepository, RepositoryId, T, CancellationToken, Task<bool>> operation)
{
return endpoints.MapPatch(pattern, async (
long installationId,
long repositoryId,
[FromBody] Payload<T> request,
InstallationService service,
IConfigurationRepository repository,
CancellationToken cancellationToken) =>
{
if (!await service.UserHasAccessToRepositoryAsync(installationId, repositoryId))
{
return Results.NotFound();
}
await repository.EnsureRepositoryAsync(repositoryId, cancellationToken);
return await operation(repository, new(repositoryId), request.Value, cancellationToken) switch
{
false => Results.Conflict(),
true => Results.NoContent(),
};
}).RequireAuthorization();
}
When attempting to compile this application with the Request Delegate Generator enabled the compilation fails with the following errors:
src\MyApplication\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs(43,118): error CS0246: The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?) [src\MyApplication\MyApplication.csproj]
src\MyApplication\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs(58,140): error CS0246: The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?) [src\MyApplication\MyApplication.csproj]
It appears that the generator is not correctly taking into account the use of generics and is trying to use the identifier T literally as a type named T rather than as a generic parameter with that name.
When I tried to make the smallest repro I could with a one file application the endpoint would compile, so I think the issue may be related to the way the code is structured in the original application in terms of namespaces etc.
I've added an application that reproduces the error in this repository. There's probably more code that needed, but it's relatively minimal.
Note that the application will not actually run as I've stripped it down to just compiling so is
missing various services registrations etc. It's just enough required to compile it successfully if the Request Delegate Generator is disabled.
Expected Behavior
The application compiles and the endpoints behave at runtime as expected.
Steps To Reproduce
- Clone the martincostello/rdg-generics-repro repository
- Run
dotnet build
Exceptions (if any)
No response
.NET Version
8.0.100-preview.6.23330.14
Anything else?
No response
Is there an existing issue for this?
Describe the bug
I have an internal application that has a user interface where various properties of a configuration object can be changed independently. To reduce duplication for this operations, various HTTP PATCH endpoints with different URLs call through a generic method that maps the endpoint based on a code pattern.
The method is essentially this where boilerplate wraps the invocation of a delegate with a generic parameter:
When attempting to compile this application with the Request Delegate Generator enabled the compilation fails with the following errors:
It appears that the generator is not correctly taking into account the use of generics and is trying to use the identifier
Tliterally as a type namedTrather than as a generic parameter with that name.When I tried to make the smallest repro I could with a one file application the endpoint would compile, so I think the issue may be related to the way the code is structured in the original application in terms of namespaces etc.
I've added an application that reproduces the error in this repository. There's probably more code that needed, but it's relatively minimal.
Note that the application will not actually run as I've stripped it down to just compiling so is
missing various services registrations etc. It's just enough required to compile it successfully if the Request Delegate Generator is disabled.
Expected Behavior
The application compiles and the endpoints behave at runtime as expected.
Steps To Reproduce
dotnet buildExceptions (if any)
No response
.NET Version
8.0.100-preview.6.23330.14
Anything else?
No response