CoreWCF icon indicating copy to clipboard operation
CoreWCF copied to clipboard

NullReferenceException in RequestDelegateHandler when wrong HTTP method is requested.

Open gvkries opened this issue 2 years ago • 1 comments

I have an duplex contract with a NetHttp(s)Binding which is using WebSockets. If this endpoint gets called with a GET request, an NullReferenceException is getting thrown by RequestDelegateHandler.HandleRequest():

System.NullReferenceException: Object reference not set to an instance of an object. at CoreWCF.Channels.RequestDelegateHandler.HandleRequest(HttpContext context) at CoreWCF.Channels.ServiceModelHttpMiddleware.InvokeAsync(HttpContext context) at CoreWCF.Description.ServiceMetadataExtension.HttpGetImpl.<>c__DisplayClass39_0.<<MetadataMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location --- at CoreWCF.Channels.MetadataMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext) at Prometheus.HttpMetrics.HttpRequestDurationMiddleware.Invoke(HttpContext context) at Prometheus.HttpMetrics.HttpRequestCountMiddleware.Invoke(HttpContext context) at Prometheus.HttpMetrics.HttpInProgressMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

The correct line is

at CoreWCF.Channels.RequestDelegateHandler.<HandleRequest>d__15.MoveNext() in /_/src/CoreWCF.Http/src/CoreWCF/Channels/RequestDelegateHandler.cs:line 104

.NET Framework is returning status code 405 (method not allowed) in this case. Maybe it is IIS that is returning this status code, I haven't checked that in detail. But I think WCF should not throw an NRE.

gvkries avatar Jun 02 '22 13:06 gvkries

Leaving open for community contribution as this is a case of a failing scenario failing the wrong way rather than a successful scenario failing so is lower priority.

mconnew avatar Jul 14 '22 16:07 mconnew