Skip to content

Request Delegate Generator fails to compile endpoint with Uri? parameter with CS8600 errors #48378

Closed

Description

@martincostello

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Enabling the Request Delegate Generator for an endpoint which has a Uri? parameter fails to compile with the following errors:

C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensios.g.cs(173,70): error CS8600: Converting null literal or possible null value to non-nullable type. [C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\LondonTravel.Site.csproj]
C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensios.g.cs(180,55): error CS8600: Converting null literal or possible null value to non-nullable type. [C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\LondonTravel.Site.csproj]
C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensios.g.cs(223,70): error CS8600: Converting null literal or possible null value to non-nullable type. [C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\LondonTravel.Site.csproj]
C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensios.g.cs(230,55): error CS8600: Converting null literal or possible null value to non-nullable type. [C:\Coding\martincostello\alexa-london-travel-site\src\LondonTravel.Site\LondonTravel.Site.csproj]

It appears that the nullability of the parameter is lost in the generated code:

- global::System.Uri redirectUri_parsed_temp = default;
+ global::System.Uri? redirectUri_parsed_temp = default;
if (Uri.TryCreate(redirectUri_temp!, UriKind.RelativeOrAbsolute, out var redirectUri_temp_parsed_non_nullable))
{
    redirectUri_parsed_temp = redirectUri_temp_parsed_non_nullable;
}
else if (string.IsNullOrEmpty(redirectUri_temp))
{
    redirectUri_parsed_temp = null;
}
else
{
    wasParamCheckFailure = true;
}

Expected Behavior

The Request Delegate Generator should emit code that compiles.

Steps To Reproduce

  1. Clone martincostello/alexa-london-travel-site@b340894
  2. Run build.ps1

Exceptions (if any)

No response

.NET Version

8.0.100-preview.4.23260.5

Anything else?

No response

Activity

  1. self-assigned this
    on May 23, 2023
  2. added
    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
    and removed on May 23, 2023
  3. mitchdenny commented on May 23, 2023

    @mitchdenny
    Member

    Thanks for reporting this. Will look into it and check why our test coverage missies this.

  4. added this to the 8.0-preview6 milestone on May 24, 2023
  5. ghost locked as resolved and limited conversation to collaborators on Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NativeAOTarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdg

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions