【问题标题】:tracking NullReferenceExceptions in sitecore在 sitecore 中跟踪 NullReferenceExceptions
【发布时间】:2012-03-24 03:23:39
【问题描述】:

我正在尝试跟踪在加载任何网页时出现在 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 中删除重要的站点核心 dll

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

您将如何跟踪此错误?

【问题讨论】:

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


    【解决方案1】:

    我遇到了与上面完全相同的问题,并且可以确认它是因为 App_Config/Include 文件夹中的 .config 文件不兼容而发生的。 .config 文件在 IIS7 上运行,但在 II6 上运行。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        当你在配置文件中有空的配置部分并且有补丁时,你也会得到这个错误,像这样

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

        【讨论】:

          【解决方案4】:

          我遇到了同样的问题,我发现你的配置文件没有 &lt;sitecore&gt; node 你会得到这样的错误!

          【讨论】:

            【解决方案5】:

            在节点之间添加 xml cmets 时我有类似的情况:

            没用:

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

            【讨论】:

            • 太棒了!九年后,我遇到了这个确切的问题。谢谢!
            【解决方案6】:

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

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

            去掉多余字符后问题解决了。

            但是更改有问题的文件的名称也可以消除异常。

            【讨论】:

              【解决方案7】:

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

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

              【讨论】:

              • 感谢您对 SlowCheetah 发表评论!
              【解决方案8】:

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

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

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

              【讨论】:

              • SlowCheetah 是否会导致这里出现问题?
              • @SayedIbrahimHashimi,根本不是,问题实际上是站点核心配置解析器,显然它无法区分 xdt 转换配置文件和常规配置文件,因此它试图了解以 Sitecore.*.config 开头的所有内容
              • Sitecore 读取并解析 App_Config\Include 下的任何文件,该文件以扩展名“.config”结尾。由于 SlowCheetah 存储 WebDAV.ContentManagementServer.Config 等配置文件 - Sitecore 将读取并尝试解析所有这些文件。
              【解决方案9】:

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2011-12-26
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2012-05-27
                相关资源
                最近更新 更多