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

RDG does not support private parameter and return types #47339

Closed
halter73 opened this issue Mar 20, 2023 · 3 comments · Fixed by #49417
Closed

RDG does not support private parameter and return types #47339

halter73 opened this issue Mar 20, 2023 · 3 comments · Fixed by #49417
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc bug This issue describes a behavior which is not expected - a bug. feature-rdg

Comments

@halter73
Copy link
Member

Given the code:

public class MyClass
{

    public static void MyMethod(IEndpointRouteBuilder app)
    {
        app.MapPost("/test-param", (MyDto param) => { });
        app.MapPost("/test-return", () => new MyDto());
    }

    private class MyDto { }
}

RDG generates code that fails to compile because MyDto is a private type. The lines that cause the compilation failure by referencing the private type are basically the same lines that fail with an undefined TUser in #47338 which is the equivalent issue about generic types.

We can skip generating MapPost and similar methods when we see a private type in the delegate signature and suggest using internal types instead. I don't think we really have an alternative unless we could somehow generate our Map extension methods directly in the same class/struct the user is calling it from. I don't know of any plans for that.

GeneratedRouteBuilderExtensions.g.cs(73,111): error CS0122: 'MyClass.MyDto' is inaccessible due to its protection level
GeneratedRouteBuilderExtensions.g.cs(88,109): error CS0122: 'MyClass.MyDto' is inaccessible due to its protection level
@halter73 halter73 added area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-rdg labels Mar 20, 2023
@mitchdenny mitchdenny added the bug This issue describes a behavior which is not expected - a bug. label Mar 21, 2023
@mitchdenny mitchdenny added this to the 8.0-preview4 milestone Mar 21, 2023
@captainsafia
Copy link
Member

I don't think we really have an alternative unless we could somehow generate our Map extension methods directly in the same class/struct the user is calling it from.

Yeah, our best option is to emit a diagnostic and fallback to the runtime behavior here. Even if we solve the problem of having to use the unspeakable names in the strongly-typed endpoint overloads (via the interceptors proposal say), we still have the dilemma of needing to reference these types in the generated request handlers when we bind parameters or emit responses.

#47338 is similar but, unlike this one, it is solvable if we implement support for generic thunks in the request delegate generator.

This is one of these issues I'd be curious to get community feedback one once RDG is out. I dunno how common it is to have private DTO classes considering that you might need to access them in unit or integration tests.

@captainsafia
Copy link
Member

I think this should be moved out of preview4 for now.

@ghost
Copy link

ghost commented Apr 11, 2023

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
@captainsafia captainsafia removed the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jun 6, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc bug This issue describes a behavior which is not expected - a bug. feature-rdg
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@halter73 @mitchdenny @captainsafia @amcasey and others