@@ -92,8 +92,13 @@ public static partial class RequestDelegateFactory
92
92
private static readonly MemberExpression FormFilesExpr = Expression . Property ( FormExpr , typeof ( IFormCollection ) . GetProperty ( nameof ( IFormCollection . Files ) ) ! ) ;
93
93
private static readonly MemberExpression StatusCodeExpr = Expression . Property ( HttpResponseExpr , typeof ( HttpResponse ) . GetProperty ( nameof ( HttpResponse . StatusCode ) ) ! ) ;
94
94
private static readonly MemberExpression CompletedTaskExpr = Expression . Property ( null , ( PropertyInfo ) GetMemberInfo < Func < Task > > ( ( ) => Task . CompletedTask ) ) ;
95
- private static readonly NewExpression EmptyHttpResultValueTaskExpr = Expression . New ( typeof ( ValueTask < object > ) . GetConstructor ( new [ ] { typeof ( EmptyHttpResult ) } ) ! , Expression . Property ( null , typeof ( EmptyHttpResult ) , nameof ( EmptyHttpResult . Instance ) ) ) ;
96
-
95
+ // Due to https://github.com/dotnet/aspnetcore/issues/41330 we cannot reference the EmptyHttpResult type
96
+ // but users still need to assert on it as in https://github.com/dotnet/aspnetcore/issues/45063
97
+ // so we temporarily work around this here by using reflection to get the actual type.
98
+ private static readonly NewExpression EmptyHttpResultValueTaskExpr = Type . GetType ( "Microsoft.AspNetCore.Http.Results, Microsoft.AspNetCore.Http.Results" ) is { } resultsType
99
+ ? Expression . New ( typeof ( ValueTask < object > ) . GetConstructor ( new [ ] { typeof ( IResult ) } ) ! , Expression . Property ( null , resultsType . GetProperty ( "Empty" ) ! ) )
100
+ : Expression . New ( typeof ( ValueTask < object > ) ) ;
101
+ private static readonly object ? EmptyHttpResultInstance = Type . GetType ( "Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult, Microsoft.AspNetCore.Http.Results" ) ? . GetProperty ( "Instance" ) ? . GetValue ( null , null ) ;
97
102
private static readonly ParameterExpression TempSourceStringExpr = ParameterBindingMethodCache . TempSourceStringExpr ;
98
103
private static readonly BinaryExpression TempSourceStringNotNullExpr = Expression . NotEqual ( TempSourceStringExpr , Expression . Constant ( null ) ) ;
99
104
private static readonly BinaryExpression TempSourceStringNullExpr = Expression . Equal ( TempSourceStringExpr , Expression . Constant ( null ) ) ;
@@ -2154,32 +2159,34 @@ static async Task ExecuteAwaited(ValueTask task)
2154
2159
2155
2160
private static ValueTask < object ? > ExecuteTaskWithEmptyResult ( Task task )
2156
2161
{
2162
+ Debug . Assert ( EmptyHttpResultInstance is not null ) ;
2157
2163
static async ValueTask < object ? > ExecuteAwaited ( Task task )
2158
2164
{
2159
2165
await task ;
2160
- return EmptyHttpResult . Instance ;
2166
+ return EmptyHttpResultInstance ;
2161
2167
}
2162
2168
2163
2169
if ( task . IsCompletedSuccessfully )
2164
2170
{
2165
- return new ValueTask < object ? > ( EmptyHttpResult . Instance ) ;
2171
+ return new ValueTask < object ? > ( EmptyHttpResultInstance ) ;
2166
2172
}
2167
2173
2168
2174
return ExecuteAwaited ( task ) ;
2169
2175
}
2170
2176
2171
2177
private static ValueTask < object ? > ExecuteValueTaskWithEmptyResult ( ValueTask valueTask )
2172
2178
{
2179
+ Debug . Assert ( EmptyHttpResultInstance is not null ) ;
2173
2180
static async ValueTask < object ? > ExecuteAwaited ( ValueTask task )
2174
2181
{
2175
2182
await task ;
2176
- return EmptyHttpResult . Instance ;
2183
+ return EmptyHttpResultInstance ;
2177
2184
}
2178
2185
2179
2186
if ( valueTask . IsCompletedSuccessfully )
2180
2187
{
2181
2188
valueTask . GetAwaiter ( ) . GetResult ( ) ;
2182
- return new ValueTask < object ? > ( EmptyHttpResult . Instance ) ;
2189
+ return new ValueTask < object ? > ( EmptyHttpResultInstance ) ;
2183
2190
}
2184
2191
2185
2192
return ExecuteAwaited ( valueTask ) ;
@@ -2507,24 +2514,6 @@ private static void FormatTrackedParameters(RequestDelegateFactoryContext factor
2507
2514
}
2508
2515
}
2509
2516
2510
- // Due to cyclic references between Http.Extensions and
2511
- // Http.Results, we define our own instance of the `EmptyHttpResult`
2512
- // type here.
2513
- private sealed class EmptyHttpResult : IResult
2514
- {
2515
- private EmptyHttpResult ( )
2516
- {
2517
- }
2518
-
2519
- public static EmptyHttpResult Instance { get ; } = new ( ) ;
2520
-
2521
- /// <inheritdoc/>
2522
- public Task ExecuteAsync ( HttpContext httpContext )
2523
- {
2524
- return Task . CompletedTask ;
2525
- }
2526
- }
2527
-
2528
2517
private sealed class RdfEndpointBuilder : EndpointBuilder
2529
2518
{
2530
2519
public RdfEndpointBuilder ( IServiceProvider applicationServices )
0 commit comments