Closed
Description
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
- Clone martincostello/alexa-london-travel-site@b340894
- Run
build.ps1
Exceptions (if any)
No response
.NET Version
8.0.100-preview.4.23260.5
Anything else?
No response