Null exception in CacheBase
See original GitHub issueHi when i run my unit test as a batch the first unit-test works but the second one fail at the following line :
response.Results = certificates.MapTo<List<PostResult>>();
with the following stack trace :
at Abp.Runtime.Caching.CacheBase.<GetAsync>d__19.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Runtime\Caching\CacheBase.cs:line 98
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Runtime.Caching.CacheExtensions.<GetAsync>d__52.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:line 38 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Configuration.SettingManager.<GetUserSettingsFromCache>d__40.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Configuration\SettingManager.cs:line 430 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Configuration.SettingManager.<GetReadOnlyUserSettings>d__38.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Configuration\SettingManager.cs:line 403 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Configuration.SettingManager.<GetSettingValueForUserOrNullAsync>d__35.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Configuration\SettingManager.cs:line 373 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Configuration.SettingManager.<GetSettingValueInternalAsync>d__31.MoveNext() in D:\Github\aspnetboilerplate\src\Abp\Configuration\SettingManager.cs:line 235 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task
1 task)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task
1 task)
at Nito.AsyncEx.AsyncContext.Run[TResult](Func1 action) at Abp.AutoMapper.AutoMapExtensions.<>c__DisplayClass2_0
4.<CreateMultiLingualMap>b__0(TMultiLingualEntity source, TDestination destination, ResolutionContext context) in D:\Github\aspnetboilerplate\src\Abp.AutoMapper\AutoMapper\AutoMapExtensions.cs:line 54
at lambda_method(Closure , List1 , List
1 , ResolutionContext )
I think it’s from the line : var defaultLanguage = multiLingualMapContext.SettingManager .GetSettingValue(LocalizationSettingNames.DefaultLanguage);
In the Automaper Extension file
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (17 by maintainers)
Top GitHub Comments
The problem only exists in unit tests.
AbpMemoryCacheManager
does not give the logger default value. CauseCreateCacheImplementation
here the logger is null.https://github.com/aspnetboilerplate/aspnetboilerplate/blob/92d5219bf8c16fa905f09dcbcc6b29f818440ba6/src/Abp/Runtime/Caching/Memory/AbpMemoryCacheManager.cs#L17-L21
https://github.com/aspnetboilerplate/aspnetboilerplate/blob/92d5219bf8c16fa905f09dcbcc6b29f818440ba6/src/Abp/Runtime/Caching/Memory/AbpMemoryCacheManager.cs#L23-L29
I found out where my NullRef came from. In the AutoMaperExtension in the method CreateMultilingualMap in the BeforeMap there is a call to SettingManager.GetSettingValue() which end’s up calling the CacheBase GetAsync Method. And the method throw an error and it trys to log it but the Logger was null. :
I’ve added this line to my Preinitialize method of my test module :
this.Configuration.ReplaceService<ILogger, NullLogger>(DependencyLifeStyle.Transient);