OK, no replies yet so... How do you go about the solution below...
Thanks...
The Exception logs on dnn.com show a number of errors from trying to cache a null object - for example
Message: System.Exception: Unhandled Error: ---> System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentNullException: Value cannot be null. Parameter name: value at System.Web.Caching.CacheEntry..ctor(String key, Object value, CacheDependency dependency, CacheItemRemovedCallback onRemovedHandler, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, Boolean isPublic) at System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic, String key, Object value, CacheDependency dependencies, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace) at System.Web.Caching.Cache.Insert(String key, Object value, CacheDependency dependencies) at DotNetNuke.Services.Cache.FileBasedCachingProvider.FBCachingProvider.Insert(String CacheKey, Object objObject, Boolean PersistAppRestart) at DotNetNuke.Common.Utilities.DataCache.SetCache(String CacheKey, Object objObject) at DotNetNuke.Modules.Forum.ForumInfo.GetForumInfo(Int32 ForumID)
and
Message: DotNetNuke.Services.Exceptions.PageLoadException: Value cannot be null. Parameter name: value ---> System.ArgumentNullException: Value cannot be null. Parameter name: value at System.Web.Caching.CacheEntry..ctor(String key, Object value, CacheDependency dependency, CacheItemRemovedCallback onRemovedHandler, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, Boolean isPublic) at System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic, String key, Object value, CacheDependency dependencies, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace) at System.Web.Caching.Cache.Insert(String key, Object value, CacheDependency dependencies) at DotNetNuke.Services.Cache.FileBasedCachingProvider.FBCachingProvider.Insert(String CacheKey, Object objObject, Boolean PersistAppRestart) at DotNetNuke.Common.Utilities.DataCache.SetCache(String CacheKey, Object objObject) at DotNetNuke.Modules.Forum.ThreadInfo.GetThreadInfo(Int32 ThreadID)
The GetThreadInfo code looks like this:
Public Shared Function GetThreadInfo(ByVal ThreadID As Integer) As ThreadInfo
Dim strCacheKey As String = ThreadInfoCacheKeyPrefix & CStr(ThreadID)
Dim objThread As ThreadInfo = CType(DataCache.GetCache(strCacheKey), ThreadInfo)
If objThread Is Nothing Then
Dim ctlThread As New ThreadController
objThread = ctlThread.ThreadGet(ThreadID)
DataCache.SetCache(strCacheKey, objThread)
End If
Return objThread
End Function
and the GetForumInfo code is very similar.
There are two problems with this code:
- There is no check the object returned is not null before attempting to save it to the cache.
- The code does not respect the Host users selection for cache performance.
Thus GetThreadInfo should be changed to:
Public Shared Function GetThreadInfo(ByVal ThreadID As Integer) As ThreadInfo
Dim strCacheKey As String = ThreadInfoCacheKeyPrefix & CStr(ThreadID)
Dim objThread As ThreadInfo = CType(DataCache.GetCache(strCacheKey), ThreadInfo)
If objThread Is Nothing Then
'thread caching settings
Dim timeOut As Int32 = ThreadInfoCacheTimeout * Convert.ToInt32(Common.Globals.PerformanceSetting)
Dim ctlThread As New ThreadController
objThread = ctlThread.ThreadGet(ThreadID)
'Cache Thread if tmeout > 0 and Thread is not null
If timeOut > 0 And objThread IsNot Nothing Then
DataCache.SetCache(strCacheKey, objThread, TimeSpan.FromMinutes(timeOut), False)
End If
End If
Return objThread
End Function
Note: PostInfo has the 2nd issue (performance setting) but does not have the first issue.