跟踪sitecore中的NullReferenceException



我正试图跟踪一个NullReferenceException,该异常在加载任何网页时都会出现在sitecore 6.5上:

[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

使这种错误难以跟踪的有趣特征如下:

1) 我在站点核心日志中得到以下错误:

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()

然而,分析功能被很好地禁用了:

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

2) 当我使用visual studio进行调试、连接到IIS并达到至少一个断点时,错误就会消失(如果我没有达到任何断点,错误就会保留)

3) 当我进行构建或触摸web.config时,错误再次出现。尚未尝试重建,因为这将从Website/bin 中删除重要的sitecore dll

关于我的环境的更多信息:visualstudio2010,IIS7,sitecore6.5,windows7

您将如何跟踪此错误?

好的,经过半天的调试和反编译,我发现问题出在(内部)类Sitecore.Configuration.ConfigPatcher上,它似乎被用于内容交付和内容创作环境的Sitecore.WebDav.config文件的xdt转换的Sitecore.WebDav.[Debug/Release].config文件卡住了。

目前,解决方法是重命名这些文件(并禁用xdt转换)

然而,这个问题应该会影响任何对非web.config文件进行xdt转换的用户(我使用的是慢速cheetah加载项)

此外,当您在带有补丁的配置文件中有空的配置部分时,也可能会出现此错误,如

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

在节点之间添加xml注释时,我也遇到了类似的情况:

不起作用:

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

如果在根节点之前添加注释,则可以正常工作。

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

您的设置中似乎缺少一个"include"配置文件。对Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList进行解压缩,试图找出哪一个(很抱歉手头没有反编译器)。Reflector有30天的试用期,或者Telerik Just Decompile是免费的。

EDIT我使用了一种名为SlowCheetah的产品,它可以根据构建配置对任何XML文件进行XML转换,而不仅仅是像VS那样的web.config。你可以NuGet。强烈推荐。

我遇到了同样的问题,我发现如果您的配置文件没有<sitecore>节点,你会得到这样的错误!

我首先要从您网站的bin文件夹中删除Sitecore.Analytic.dll。你不需要dll,因为你禁用了分析,但正如你从堆栈中看到的,这个dll中有一个错误。

我遇到了类似的问题,结果发现我的配置文件格式不正确。更具体地说,我一定在配置文件的开头粘贴了一些随机字符串:

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

删除多余字符后,问题得到了解决。

然而,更改有问题文件的名称也可以消除异常。

我遇到了完全相同的问题(我的堆栈跟踪与发布的相同),结果发现App_ConfigInclude文件夹中的.config文件格式错误。修复了配置,我的网站加载没有问题。

我遇到了与上面完全相同的问题,可以确认这是因为App_config/Include文件夹中的.config文件不兼容。.config文件在IIS7上工作,但在II6上不工作。

要想弄清这个问题的真相,我最好的建议是发一条乏味的试错消息。删除任何可疑的.config文件,直到网站启动并运行(或恢复到原始.config文件)。开始逐个添加每个.config文件,直到您发现破坏网站并导致上述问题的文件。

最新更新