aspnet/HttpAbstractions

Middleware exception message is ambiguous

agegould opened this issue · 2 comments

When the framework attempts to locate the 'Invoke' or 'InvokeAsync' method on a middleware class, an exception is thrown if it cannot locate a suitable method, however, the exception message is ambiguous as it does not provide any details of the name of the middleware class that it was attempting to invoke when the exception was thrown.

An example of the exception message is provided below:-
No details of the class name are included, which makes it very difficult to locate the issue.

An error occurred while starting the application.
InvalidOperationException: No public 'Invoke' or 'InvokeAsync' method found.
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass4_0.b__0(RequestDelegate next)
InvalidOperationException: No public 'Invoke' or 'InvokeAsync' method found.
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass4_0.b__0(RequestDelegate next)
Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Show raw exception details
System.InvalidOperationException: No public 'Invoke' or 'InvokeAsync' method found.

at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.b__0(RequestDelegate next)

at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()

at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

@jkotalik Adding the middleware name to the exception message should be straightforward.

This issue was moved to dotnet/aspnetcore#2692