Sitecore: Seemingly Random errors appear

2019-08-12 03:31发布

问题:

we are experiencing some very odd errors in our installation. Some times out of nowhere Sitecore throws an error:

Assert: Value Cannot be null. Parameter: Item. 

The closest i have come to identifying the problem is narrowing it down to either an index or the web database.

Anyway, if I log into sitecore the Item is just missing, i can fix it in 3 ways:

  • Rebuild the index.
  • Recycle app pool
  • iisreset

Does any of you have an idea why this might be happening? We are running Sitecore.NET 6.5.0 (rev. 120706). Any help will be deeply appreciated.

回答1:

You are describing a system stability issue, so I recommend opening a ticket with Sitecore support (http://support.sitecore.net). This sort of issue is difficult to troubleshoot over Stack Overflow, since we do not have access to your logs and configuration.

When opening the ticket, I recommend using the Support Package Generator which bundles up all the information (Web.config, App_Config files, IIS settings, Sitecore log files) that Sitecore Support needs to troubleshoot the issue. It's a pretty nifty tool.

That said, from what you describe, it sounds like the issue is related to caching. The fact that restarting IIS resolves the issue indicates that the item is in the Web database, but the runtime doesn't see it. You can prove out whether this is the issue by clearing cache using the /sitecore/admin/cache.aspx screen. If your cache is not getting updated properly, you should review your configuration against the guidelines in the SDN Scaling Guide.



回答2:

Based on knowing you're using the Advanced Database Crawler, your issue may be how you're converting a SkinnyItem to an Item. I've had this issue before. If you look at the SkinnyItem.cs class, there's a GetItem() method to convert it into an Item. You can see it uses the database to get the item by its ID, language, and version number. Its possible that when you publish from master to web, you are publishing a new version # of an existing item and thus the new version exists in the web DB, but the index is not updated and references the old version. So, this GetItem() call would use the previous version # and the item would be null. One way to fix this is instead of calling that GetItem() method, just use your own code to get the latest version of that item from Sitecore, e.g.

Item item = Sitecore.Context.Database.GetItem(someSkinnyItem.ItemID);

Instead of

Item item = someSkinnyItem.GetItem();

Here's an example flow:

  • Foo item created in master DB as version 1.
  • Publish Foo to web
  • Index will pick up version 1 in web DB and put in index.
  • Any querying code against index will convert the SkinnyItem to an Item via that GetItem() method and will pass 1 as the version #.
  • Page will load, no error in log
  • Back in master, create version 2 of Foo and publish.
  • Index may not get updated right away or even if configured wrong.
  • Code that looks against index will call GetItem() and still call with version 1 since that's in the index
  • But when you published, web no longer has version 1, it now has version 2, and thus that specific version of that item Foo is null
  • Error shows in log

On a similar note, here's a blog post by Alex Shyba (creator of the ADC) on how to sync HTML cache clearing with the index updates. That may help.