tracking NullReferenceExceptions in sitecore

谁说胖子不能爱 提交于 2019-12-01 16:43:19

问题


i'm trying to track a NullReferenceException that shows up on sitecore 6.5 at loading any webpage:

[NullReferenceException: Object reference not set to an instance of an object.]
   Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +133
   Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
   Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +680
   Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +63
   Sitecore.Configuration.Factory.GetConfiguration() +347
   Sitecore.Diagnostics.LoggerFactory..cctor() +67

[TypeInitializationException: The type initializer for 'Sitecore.Diagnostics.LoggerFactory' threw an exception.]
   Sitecore.Diagnostics.LoggerFactory.GetLogger(Type type) +17
   Sitecore.Diagnostics.Log.Error(String message, Exception exception, Type ownerType) +93
   Sitecore.Diagnostics.Log.Error(String message, Type ownerType) +45
   Sitecore.Configuration.Factory.LoadAutoIncludeFiles(ConfigPatcher patcher, String folder) +680
   Sitecore.Configuration.Factory.LoadAutoIncludeFiles(XmlNode element) +63
   Sitecore.Configuration.Factory.GetConfiguration() +347
   Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert) +82
   Sitecore.Configuration.Factory.GetConfigNode(String xpath) +29
   Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList() +114
   Sitecore.Resources.Media.UploadWatcher..cctor() +51

[TypeInitializationException: The type initializer for 'Sitecore.Resources.Media.UploadWatcher' threw an exception.]
   Sitecore.Resources.Media.UploadWatcher..ctor() +0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +23
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
   System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +231
   System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1365
   Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleReflectionUtil.GetIntegratedModuleCollection(HttpApplication target, IntPtr appContext) +33
   Microsoft.Web.Infrastructure.DynamicModuleHelper.CriticalStatics.Init(HttpApplication context) +179
   Microsoft.Web.Infrastructure.DynamicModuleHelper.IntegratedDynamicModule.Init(HttpApplication context) +6
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +517
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9087676
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

the interesting characteristics that make this error hard to track are the following:

1) i get the following error in the sitecore log:

Exception: System.InvalidOperationException
Message: 'analytics' connection string is not defined
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.IsNotNull(Object value, String message)
   at Sitecore.Diagnostics.Assert.ResultNotNull[T](T result, String message)
   at Sitecore.Analytics.Data.DataAccess.DataAdapters.DataAdapterManager.ConnectionStrings.get_AnalyticsSettings()
   at Sitecore.Analytics.Data.DataAccess.DataAdapters.DataAdapterManager.ConnectionStrings.get_Analytics()
   at Sitecore.Analytics.Data.DataAccess.DataAdapters.Sql.SqlServer.SqlServerDataAdapterProvider..ctor()

however analytics is very well disabled:

<setting name="Analytics.DisableDatabase" value="true" />
...
<setting name="Analytics.Enabled" value="false" />

2) the error goes away when i debug with visual studio, attach to IIS, and hit at least one breakpoint (if i don't hit any breakpoint, the error stays)

3) the error shows up again when i do a build, or touch web.config. Haven't tried rebuild, as that will delete important sitecore dlls from Website/bin

more info about my environment: visual studio 2010, IIS 7, sitecore 6.5, windows 7

how would you track this error?


回答1:


Ok after half day of debugging and decompiling i found out the problem was the (internal) class Sitecore.Configuration.ConfigPatcher, it seems to choke with Sitecore.WebDav.[Debug/Release].config files that are used for xdt transformations of the Sitecore.WebDav.config file for the content delivery and content authoring environment.

For now, the workaround is rename these files (and disable xdt transformations)

However, this problem should affect any user of xdt transformations for non-web.config files (i'm using slow cheetah add-in)




回答2:


Also you can get this error when you have empty configuration section in config file with patching, like this

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

</configuration>



回答3:


I had something similar when adding xml comments between nodes:

Did not work:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <!-- not used in a delivery node -->
    <sitecore />
</configuration>

If you add the comment before the root node, it works.

<!-- not used in a delivery node -->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore />
</configuration>



回答4:


Looks like an "include" config file is missing from your setup. Decompile Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList to try to work out which one (sorry haven't got a decompiler handy). Reflector comes with a 30-day trial or Telerik Just Decompile is free.

EDIT I use a product called SlowCheetah which does XML transformations based on build configuration for any XML file, not just web.config like VS does. You can NuGet it. Highly Recommended.




回答5:


I had the same problem, i found out if your config files don't have the <sitecore> node you will get a error like this!




回答6:


I would start with removing Sitecore.Analytics.dll from the bin folder of your website. You don't need the dll as you disabled analytics, but as you can see from your stacktrace, there is an error inside this dll.




回答7:


I had similar problem and it turned out I had malformed config file. More specifically I must have pasted some random string at the beginning of the config file:

some_random_string<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

After removing redundant characters problem was solved.

However changing the name of problematic file also get rid of the exception.




回答8:


I had the exact same problem (my stack trace was the same as the one posted) and it turned out to be a malformed .config file in the App_Config\Include folder. Fixed the config and my site loaded without problems.




回答9:


I had the exact same issue encountered above and can confirm it happened because of an incompatible .config file in the App_Config/Include folder. The .config file was working on IIS7, but not II6.

My best advice to get to the bottom of this issue is a tedious trial and error message. Remove any suspect .config files until the website is up and running (or revert to original .config files). Start adding each .config file one by one, until you discover the file that breaks the site and causes the above issue.



来源:https://stackoverflow.com/questions/9587257/tracking-nullreferenceexceptions-in-sitecore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!