Sitecore NullReferenceException on GetBrowserClass

2019-08-02 13:54发布

问题:

It was a beautiful day, and I came into work and Sitecore randomly gives me this:

[NullReferenceException: Object reference not set to an instance of an object.]
   Sitecore.UIUtil.GetBrowserClassString() +491
   Sitecore.sitecore.login.LoginPage.AddBrowserAttributes() +134
   Sitecore.sitecore.login.LoginPage.OnPreRender(EventArgs e) +434
   System.Web.UI.Control.PreRenderRecursiveInternal() +112
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4296

Not only was this an interruption to said day, it was altogether out of nowhere. It does not appear that I or any on my team have made any affecting changes, and it's been working fine.

Any ideas?

回答1:

We had this issue for a MultiSite Sitecore instance using Sitecore 6.5. The issue was that, as @WeekendWarrior alluded to, the Capabitilities Type was null. I found the solution on the Sitecore forum; however, I thought it'd be useful duplicate the simple, quick-fix part of the posted answer here because you need a Sitecore account to access the forum:

In your default site Content Editor, locate /sitecore/layout/Devices/Default and in the field Capabilities Type - Type, Assembly enter:

Sitecore.Web.Configuration.InternetExplorerCapabilities, Sitecore.Kernel

Save, then publish that item.



回答2:

Digging into GetBrowserClassString() with reflector (Sitecore.Kernel.dll), the only possible LOC that could trigger the null reference errors is:

Client.Device.Capabilities.Browser.MajorVersion // in the Sitecore namespace

Did you change your user agent string with a plugin? this might trip up this line of code. Regardless, I recommend that you put this line of code in your solution (or another test sitecore solution, debug it and see what part of it is null.