Asp.net core 从服务引发异常时,未调用ExceptionFilterAttribute.OneException

Asp.net core 从服务引发异常时,未调用ExceptionFilterAttribute.OneException,asp.net-core,.net-core,Asp.net Core,.net Core,无法理解ExceptionFilterAttribute何时调用OneException方法 假设我有两个注册的过滤器: filters.Add<ExceptionFilter>(); filters.Add<ActionExecutionFilter>(); 解决了这个难题。问题根本不在.net核心或异常属性中。我正在为DataManager和dataAccess实例使用拦截器,因此在我在其中一个实例中抛出异常后,拦截器将该错误包装并作为正常结果返回,这会导致OnRe

无法理解ExceptionFilterAttribute何时调用OneException方法

假设我有两个注册的过滤器:

filters.Add<ExceptionFilter>();
filters.Add<ActionExecutionFilter>();

解决了这个难题。问题根本不在.net核心或异常属性中。我正在为DataManager和dataAccess实例使用拦截器,因此在我在其中一个实例中抛出异常后,拦截器将该错误包装并作为正常结果返回,这会导致OnResultExecuted调用中包含异常。

这很奇怪。介意粘贴异常过滤器的内容吗?另外,
throweexceptionmethod
是否是一种异步方法(返回
Task
Task
)?如果是,您是否正在等待?如果没有,异步方法的异常将不会被捕获,除非调用a)
wait
ed或b)
task.Result
(阻塞、错误、抛出聚合异常而不是特定异常)或c)
task.getwaiter().GetResult()
。感谢您的帮助。
public ActionResult SomeActionMethod()
{
    throw new Exception("this one calls OnException");
    //Logic
}

public ActionResult SomeActionMethod()
{
    var result = this._injectedService.ThrowExceptionMethod(); // --> This one doesn't call OnException if it appears
    //Logic
}