跟踪sitecore中的NullReferenceExceptions

时间:2012-03-06 15:59:03

标签: visual-studio-2010 iis-7 sitecore sitecore6 slowcheetah

我正在尝试跟踪在加载任何网页时在sitecore 6.5上显示的NullReferenceException:

[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)我在sitecore日志中收到以下错误:

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

有关我的环境的更多信息:visual studio 2010,IIS 7,sitecore 6.5,windows 7

您将如何跟踪此错误?

9 个答案:

答案 0 :(得分:4)

好了半天的调试和反编译后我发现问题是(内部)类Sitecore.Configuration.ConfigPatcher,它似乎与用于Sitecore.WebDav的xdt转换的Sitecore.WebDav.[Debug/Release].config文件窒息.config文件,用于内容交付和内容创作环境。

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

但是,这个问题应该影响任何非web.config文件的xdt转换用户(我使用的是慢速猎豹插件)

答案 1 :(得分:4)

如果配置文件中有空配置部分并且有补丁,那么你也可以得到这个错误,比如

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

</configuration>

答案 2 :(得分:3)

在节点之间添加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>

答案 3 :(得分:1)

您的设置中似乎缺少“包含”配置文件。 反编译Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList以尝试找出哪一个(抱歉没有反编译器方便)。 Reflector提供30天的试用版或Telerik Just Decompile是免费的。

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

答案 4 :(得分:1)

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

答案 5 :(得分:0)

我首先要从您网站的 bin 文件夹中删除 Sitecore.Analytics.dll 。您在禁用分析时不需要dll,但正如您在堆栈跟踪中看到的那样,此dll中存在错误。

答案 6 :(得分:0)

我有类似的问题,结果我的配置文件格式错误。更具体地说,我必须在配置文件的开头粘贴一些随机字符串:

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

删除冗余字符后问题解决了。

但是,更改有问题文件的名称也可以摆脱异常。

答案 7 :(得分:0)

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

答案 8 :(得分:0)

我遇到了与上面遇到的完全相同的问题,并且由于App_Config / Include文件夹中存在不兼容的.config文件,因此可以确认它已发生。 .config文件适用于IIS7,但不适用于II6。

我最好的建议是解决这个问题的底部是一个乏味的试验和错误消息。删除所有可疑的.config文件,直到网站启动并运行(或恢复为原始.config文件)。开始逐个添加每个.config文件,直到您发现破坏网站的文件并导致上述问题。