November Happy Hour will be moved to Thursday December 5th.

CatalogContext.Current.GetCatalogNode caching issue

Vote:
 

Sometimes one needs to determine if particular catalog node code is used in previous versions of Commerce we used to call following method to verify, if it does exist, if not - null was returned.

var node = CatalogContext.Current.GetCatalogNode(code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo));

    

However now in Commerce 7.5(7.6.1), if it does not exist(value is null), it tries to cache it anyway and fails with following exception:

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, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
   at Mediachase.Commerce.Engine.Caching.MasterKeyCache.Insert(String key, Object value, TimeSpan duration, CacheDependency dependency, CacheItemPriority priority, CacheItemRemovedCallback callback)
   at Mediachase.Commerce.Catalog.Managers.CatalogNodeManager.ExecuteThroughCache[T](Boolean useCache, String cacheKey, TimeSpan timeout, Func`1 load)
   at Mediachase.Commerce.Catalog.Managers.CatalogNodeManager.GetCatalogNode(String code, CatalogNodeResponseGroup responseGroup)
...
    

    

How then I'm supposed to check for existence by catching exception if I already know catalog node code?
Also this method is not marked as deprecated so it should work as expected and not throw exception.

#86004
May 10, 2014 13:23
Vote:
 

Before proceeding try to call following method:

var node = CatalogNodeManager.GetCatalogNodeDto(code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo));

    

And then check count of nodes loaded:

var count = node.CatalogNode.Count;

    

If count will be zero - EPiServer anyway wil try to insert `null` in cache which is guarded by .Net Framework.

Does catalog by that code exists in Commerce?

#86005
May 10, 2014 14:33
Vote:
 

Yes, this problem occurs on catalog nodes that does not exist.

Yes, this approach works for catalog nodes that does not exist:

var node = CatalogContext.Current.GetCatalogNodeDto(code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo));

    

But that does not change fact that this method does not work:

var node = CatalogContext.Current.GetCatalogNode(code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo));

    

GetCatalogNode method has bug in it and it should return null if catalogNode is not found and not throw exception:

System.ArgumentNullException: Value cannot be null.

#86009
Edited, May 12, 2014 7:48
Vote:
 

Hi,

Yes, that sounds like a bug. I will file a bug report to see what we can do to improve the situation.

Thank you for bringing this to our attention.

Regards.

/Q

#86010
May 12, 2014 8:34
Vote:
 

Just upgraded other project to 7.6.0 and got exactly the same error, decided to check out 7.9.0 and there is no error anymore, its fixed somewere between 7.6.0 and 7.9.0

#88406
Jul 11, 2014 13:48
Vote:
 

Yes, it's  been fixed sin Commerce Core 7.8.4:

http://world.episerver.com/Documentation/Release-Notes/ReleaseNote/?releaseNoteId=114489

Thank you for your feedback!

/Q

#88431
Jul 12, 2014 16:22
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.