NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
863 stars 171 forks source link

Issue when paired with Microsoft.AspNetCore.Mvc.Versioning #134

Open rheone opened 6 years ago

rheone commented 6 years ago

When pairing StackExchange.Exceptional.AspNetCore 2.0.0-rc2.* with Microsoft.AspNetCore.Mvc.Versioning 2.2.0 and configuring versioning to ReportApiVersions will throw System.InvalidOperationException: Headers are read-only, response has already started when attempting, and failing, to access the the exceptional page / task.

I'm not sure if this is directly an issue with Exceptional, or with how Microsoft.AspNetCore.Mvc.Versioning is handling headers.

here is my configuration:

public class Startup
{
   // ... other unimportant configuration
   public IServiceProvider ConfigureServices(IServiceCollection services)
   {
         // ... other service configuration
         services.AddExceptional(configuration.GetSection("Exceptional"));
         // ... configure MVC
         services.AddApiVersioning(options =>
                             {
                                options.AssumeDefaultVersionWhenUnspecified = true;
                                options.ReportApiVersions = true;   // when set to true reporting api versions conflicts with StackExchange.Exceptional
                                options.DefaultApiVersion = new ApiVersion(1, 0);
                                options.ApiVersionReader = new HeaderApiVersionReader("api-version");
                             });
         // ... other service configuration
   }                             
}

setting ReportApiVersions to true will

... When this property is set to true, the HTTP headers "api-supported-versions" and "api-deprecated-versions" will be added to all valid service routes...

e.g. response header are modified, and Exceptional begins to fail