AspectCore.DynamicProxy.AspectInvocationException: Exception has been thrown by the aspect of an invocation. ---> Object reference not set to an instance of an object.
wannvmi opened this issue · comments
wannvmi commented
使用异步方法加 RedisCache
和MemoryCache
Attribute会报错
if (context.ServiceMethod.IsReturnTask())
{
context.ReturnValue = Task.FromResult(JsonConvert.DeserializeObject(value,
context.ServiceMethod.ReturnType.GenericTypeArguments[0]));
}
context.ReturnValue
是空值
"Message": "Exception has been thrown by the aspect of an invocation. ---> Object reference not set to an instance of an object.."
"InnerException":"Object reference not set to an instance of an object.",
returnValue
Id = 405, Status = RanToCompletion, Method = "{null}", Result = "19"
异步读取redis key 返回null
异步写入报错
同步方法都是可用的
AspectCore.DynamicProxy.AspectInvocationException: Exception has been thrown by the aspect of an invocation. ---> Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at ActualCombat.Hotel.Core.Attributes.RedisCacheAttribute.Invoke(AspectContext context, AspectDelegate next) in E:\XWwork\Git\AC.Hotel\src\ActualCombat.Hotel.Core\Attributes\RedisCacheAttribute.cs:line 61
at AspectCore.DynamicProxy.AspectActivator.InvokeTask[TResult](AspectActivatorContext activatorContext)
--- End of inner exception stack trace ---
at AspectCore.DynamicProxy.AspectActivator.InvokeTask[TResult](AspectActivatorContext activatorContext)
at ActualCombat.Hotel.Api.Controllers.UserController.GetCountAsync() in E:\XWwork\Git\AC.Hotel\src\ActualCombat.Hotel.Api\Controllers\UserController.cs:line 56
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask`1.get_Result()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()