Today I ran into a strange problem that made no sense to me. Here is a summary:
Inside the method, I check the cached element as shown below:
private async Task<RatesStatus> getRatesStatusAsync() {
if (_currentHttpContext != null) {
var cachedRatesStatusObj = HttpContext.Current.Cache[Constants.RATESSTATUS_CACHE_KEY_NAME];
if (cachedRatesStatusObj != null)
return (RatesStatus)cachedRatesStatusObj;
}
cacheRatesStatusObject(ratesStatus);
}
Here is HttpContext.Currentnot null as expected in an ASP.NET application. Then, inside the method cacheRatesStatusObject, I check to see if it HttpContext.Currentis null or not:
private void cacheRatesStatusObject(RatesStatus ratesStatus) {
//...
//Seeing if HttpContext.Current is null or not first.
//and it is null here...
if (HttpContext.Current == null)
return;
//...
}
And he is there null. I donβt know what is going on here. Any thoughts?
source
share