Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenAPI] error CS0308: The non-generic type 'TypeName' cannot be used with type arguments #61035

Open
1 task done
martincostello opened this issue Mar 20, 2025 · 1 comment · May be fixed by #61145
Open
1 task done
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi

Comments

@martincostello
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In verifying some changes noted in #60977 (comment) with the latest nightly build for preview 3, I hit two new issues in both of the referenced apps. They're all related to generics, so they're probably the same single issue so I'll list them all here rather than a separate one per compiler error.

From martincostello/adventofcode@85d3410:

C:\Coding\martincostello\adventofcode\artifacts\obj\AdventOfCode.Site\debug\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(536,177): error CS0308: The non-generic type 'Task' cannot be used with type arguments [C:\Coding\martincostello\adventofcode\src\AdventOfCode.Site\AdventOfCode.Site.csproj]
C:\Coding\martincostello\adventofcode\artifacts\obj\AdventOfCode.Site\debug\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(611,212): error CS7003: Unexpected use of an unbound generic name [C:\Coding\martincostello\adventofcode\src\AdventOfCode.Site\AdventOfCode.Site.csproj]

From martincostello/alexa-london-travel-site@4b85230 (which includes errors for #61019):

C:\Coding\martincostello\alexa-london-travel-site\artifacts\obj\LondonTravel.Site\release\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(466,178): error CS0673: System.Void cannot be used from C# -- use typeof(void) to get the void type object
C:\Coding\martincostello\alexa-london-travel-site\artifacts\obj\LondonTravel.Site\release\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(488,247): error CS0308: The non-generic type 'Expression' cannot be used with type arguments
C:\Coding\martincostello\alexa-london-travel-site\artifacts\obj\LondonTravel.Site\release\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(507,237): error CS0308: The non-generic type 'Expression' cannot be used with type arguments
C:\Coding\martincostello\alexa-london-travel-site\artifacts\obj\LondonTravel.Site\release\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(531,177): error CS0673: System.Void cannot be used from C# -- use typeof(void) to get the void type object
C:\Coding\martincostello\alexa-london-travel-site\artifacts\obj\LondonTravel.Site\release\Microsoft.AspNetCore.OpenApi.SourceGenerators\Microsoft.AspNetCore.OpenApi.SourceGenerators.XmlCommentGenerator\OpenApiXmlCommentSupport.generated.cs(538,175): error CS0673: System.Void cannot be used from C# -- use typeof(void) to get the void type object

I'll enable the code output shortly and paste the relevant lines of code.

Expected Behavior

The applications compile.

Steps To Reproduce

Clone either of the two commits and build the solution:

  1. martincostello/adventofcode@85d3410
  2. martincostello/alexa-london-travel-site@4b85230

Exceptions (if any)

No response

.NET Version

10.0.100-preview.3.25169.19

Anything else?

No response

@martincostello martincostello added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi labels Mar 20, 2025
@captainsafia
Copy link
Member

From martincostello/adventofcode@85d3410:

The first error here appears to be related to the fact that our ReplacGenericArguments logic isn't super resilient at generic types that might contain comma separators for tuples or other reasons. For example, Task<(int, string)> becomes Task<,> because we check for comma count to determine the number of generic type arguments which breaks this. This is fixable.

The second error is related to the fact that we're using an open-generic inside a tuple which is prohibited. I think we can fix this by not emitting an open generic in this case, although I think we have a scenario where we can't source generate for types that return something like (int, Dictionary<T, string>) since we can't resolve the T ahead of time.

From martincostello/alexa-london-travel-site@4b85230 (which includes errors for #61019):

As you noticed, the System.Void are the same as what I identified in #61019 (comment).

The Expression one is the same as the first error above: brittle handle of generics with tuples or nested generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants