title: ASP.NET Core MVC MiddlewareFilter exception not meaningful
body: <p>Currently I have a problem with thrown exceptions when enabling my MiddlewareFilter. As soon as I add the filter even the developer exceptions are quite meaningless (the complete stacktrace is missing).</p>
  
  <pre><code>services.AddMvc(options =&gt; options.Filters.Add(new MiddlewareFilterAttribute(typeof(MyFilter))))
  
  public class MyFilter
  {
      public void Configure(IApplicationBuilder applicationBuilder, RequestLocalizationOptions options)
      {
          applicationBuilder.UseRequestLocalization(options);
      }
  }
  </code></pre>
  
  <p>Stacktrace with filter:</p>
  
  <pre><code>System.Exception: Test Exception
             at Microsoft.AspNetCore.Mvc.Internal.MiddlewareFilterBuilder.&lt;&gt;c.&lt;&lt;BuildPipeline&gt;b__8_0&gt;d.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.&lt;Invoke&gt;d__4.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextResourceFilter&gt;d__22.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
             at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
             at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeAsync&gt;d__20.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.Builder.RouterMiddleware.&lt;Invoke&gt;d__4.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.&lt;Invoke&gt;d__3.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at SimpleInjector.SimpleInjectorAspNetCoreIntegrationExtensions.&lt;&gt;c__DisplayClass0_0.&lt;&lt;UseSimpleInjectorAspNetRequestScoping&gt;b__0&gt;d.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Swashbuckle.AspNetCore.SwaggerUi.SwaggerUiMiddleware.&lt;Invoke&gt;d__5.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Swashbuckle.AspNetCore.SwaggerUi.RedirectMiddleware.&lt;Invoke&gt;d__4.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.&lt;Invoke&gt;d__6.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.&lt;Invoke&gt;d__3.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.VisualStudio.Web.BrowserLink.BrowserLinkMiddleware.&lt;ExecuteWithFilter&gt;d__7.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.&lt;Invoke&gt;d__7.MoveNext()
          --- End of stack trace from previous location where exception was thrown ---
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
             at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.&lt;Invoke&gt;d__7.MoveNext()
  </code></pre>
  
  <p>Stacktrace without filter:</p>
  
  <pre><code>System.Exception: Test Exception
     at MyProject.MyRepository.&lt;Fetch&gt;d__9.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at MyProject.MyHandler.&lt;Handle&gt;d__7.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at MyProject.MyController.&lt;Index&gt;d__19.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;d__27.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;d__25.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextResourceFilter&gt;d__22.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeAsync&gt;d__20.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Builder.RouterMiddleware.&lt;Invoke&gt;d__4.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.&lt;Invoke&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at SimpleInjector.SimpleInjectorAspNetCoreIntegrationExtensions.&lt;&gt;c__DisplayClass0_0.&lt;&lt;UseSimpleInjectorAspNetRequestScoping&gt;b__0&gt;d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Swashbuckle.AspNetCore.SwaggerUi.SwaggerUiMiddleware.&lt;Invoke&gt;d__5.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Swashbuckle.AspNetCore.SwaggerUi.RedirectMiddleware.&lt;Invoke&gt;d__4.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.&lt;Invoke&gt;d__6.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.&lt;Invoke&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.VisualStudio.Web.BrowserLink.BrowserLinkMiddleware.&lt;ExecuteWithFilter&gt;d__7.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.&lt;Invoke&gt;d__7.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.&lt;Invoke&gt;d__7.MoveNext()
  </code></pre>
  
  <p>So basically I'm unable to track down exceptions when enabling the filter. Do you have any ideas how to correct this? (I need to use MiddlewareFilters)</p>