Sitecore 服务器错误";对象引用未设置为对象的实例;从分支插入后

Sitecore 服务器错误";对象引用未设置为对象的实例;从分支插入后,sitecore,sitecore7.2,Sitecore,Sitecore7.2,一切正常,但在Sitecore从7.0更新到7.2后,从分支创建站点时,我看到以下服务器错误 [NullReferenceException: Object reference not set to an instance of an object.] Sitecore.Nexus.Data.DataCommands.AddFromTemplateCommand.(Item , Item , String , ID , ID , String , SafeDictionary`2 ) +4

一切正常,但在Sitecore从7.0更新到7.2后,从分支创建站点时,我看到以下服务器错误

[NullReferenceException: Object reference not set to an instance of an object.]
   Sitecore.Nexus.Data.DataCommands.AddFromTemplateCommand.(Item , Item , String , ID , ID , String , SafeDictionary`2 ) +420
   Sitecore.Nexus.Data.DataCommands.AddFromTemplateCommand.(Item , Item , String , ID , ID , String , SafeDictionary`2 ) +856
   Sitecore.Nexus.Data.DataCommands.AddFromTemplateCommand.(String , Item , Item , ID ) +569
   Sitecore.Data.Engines.DataCommands.AddFromTemplateCommand.DoExecute() +113
   Sitecore.Data.Engines.EngineCommand`2.Execute() +121
   Sitecore.Data.Engines.DataEngine.AddFromTemplate(String itemName, ID templateId, Item destination, ID newId) +101
   Sitecore.Data.Managers.ItemProvider.AddFromTemplate(String itemName, ID templateId, Item destination, ID newId) +363
   Sitecore.Data.Managers.ItemManager.AddFromTemplate(String itemName, ID templateId, Item destination, ID newItemId) +203
   Sitecore.Data.Managers.ItemManager.AddFromTemplate(String itemName, ID templateId, Item destination) +286
   Sitecore.Data.Items.Item.Add(String name, BranchId branchId) +110
   Sitecore.Workflows.WorkflowContext.AddItem(String name, BranchItem branch, Item parent) +279
   Sitecore.Shell.Framework.Commands.AddMaster.Add(ClientPipelineArgs args) +803

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +76
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +211
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   Sitecore.Nexus.Pipelines.NexusPipelineApi.Resume(PipelineArgs args, Pipeline pipeline) +398
   Sitecore.Web.UI.Sheer.ClientPage.ResumePipeline() +285
   Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e) +547
   Sitecore.Shell.Applications.ContentManager.ContentEditorPage.OnPreRender(EventArgs e) +25
   System.Web.UI.Control.PreRenderRecursiveInternal() +113
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4297
一个网站创建正确,我认为没有问题

据我所知,错误发生在item:addmaster命令中:

<command name="item:addmaster" type="Sitecore.Shell.Framework.Commands.AddMaster,Sitecore.Kernel" />

Sitecore的事件模型中似乎发生了变化,但我对此缺乏了解。

尝试包装对
Sitecore.Data.Engines.DataEngine.AddFromTemplate的任何调用,或者使用
EventDisabler
添加项目的任何调用。由于异常是在
Nexus
中引发的,因此很难说问题的确切原因是什么

当我遇到类似的问题时,我有一个理论,即可能有一些事件触发并导致异常。错误并不总是发生,而且很难找到错误的原因,因为它是在
Nexus
中抛出的。在尽我所能进行调查和调试时(对Nexus进行除错、反编译、通读并调试到
Nexus
),我发现有几个API调用会引发事件(例如
AddVersion
AddMaster
,等等)。当我将代码包装到一个
EventDisabler
中时,我认为我的理论得到了证实

我的类似经历

我刚刚在Sitecore 8.1.2中遇到了几乎相同的问题。我的代码与OP中的代码之间的区别在于,我通过添加到
AddFromTemplate
管道中的处理器利用了新的(我相信比OP更新的)ItemProvider

下面是我添加的处理器。我使用此处理器运行规则,并收到了完全相同的错误,直到我在
事件禁用程序中结束了对
Sitecore.Data.Engines.DataEngine.AddFromTemplate
(必须调用,否则该项将永远不会实际创建)的调用

修复前的处理器

    public override void Process([NotNull] AddFromTemplateArgs args)
    {
        ID id; 

        if (args.Aborted 
            || string.IsNullOrWhiteSpace(RuleFolderId) 
            || !Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database)
            || !ID.TryParse(RuleFolderId, out id))
        {
            return;
        }

        Assert.HasAccess(args.Destination.Access.CanCreate(), "You do not have permission to create items here.");

        using (new EventDisabler()) // fixes the exception from nexus
        {
            var item = args.Destination.Database.Engines.DataEngine.AddFromTemplate(
                args.ItemName,
                args.TemplateId,
                args.Destination,
                args.NewId);

            args.ProcessorItem = item;
            args.Result = item;
        }

        var ruleContext = new PipelineArgsRuleContext<AddFromTemplateArgs>(args);

        RuleManager.RunRules(ruleContext, id);
    }
public重写无效进程([NotNull]AddFromTemplateArgs args)
{
身份证;
如果(args)已中止
||string.IsNullOrWhiteSpace(RuleFolderId)
||!Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database)
||!ID.TryParse(RuleFolderId,out ID))
{
返回;
}
Assert.HasAccess(args.Destination.Access.CanCreate(),“您没有在此处创建项目的权限”);
//此调用引发异常,这是此调用的必需调用
//处理器,否则将不会实际创建该项
var item=args.Destination.Database.Engines.DataEngine.AddFromTemplate(
args.ItemName,
args.TemplateId,
args.目的地,
args.NewId);
args.ProcessorItem=项目;
args.Result=项目;
var ruleContext=新的PipelineArgsRuleContext(args);
RuleManager.RunRules(ruleContext,id);
}
具有修复程序的处理器

    public override void Process([NotNull] AddFromTemplateArgs args)
    {
        ID id; 

        if (args.Aborted 
            || string.IsNullOrWhiteSpace(RuleFolderId) 
            || !Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database)
            || !ID.TryParse(RuleFolderId, out id))
        {
            return;
        }

        Assert.HasAccess(args.Destination.Access.CanCreate(), "You do not have permission to create items here.");

        using (new EventDisabler()) // fixes the exception from nexus
        {
            var item = args.Destination.Database.Engines.DataEngine.AddFromTemplate(
                args.ItemName,
                args.TemplateId,
                args.Destination,
                args.NewId);

            args.ProcessorItem = item;
            args.Result = item;
        }

        var ruleContext = new PipelineArgsRuleContext<AddFromTemplateArgs>(args);

        RuleManager.RunRules(ruleContext, id);
    }
public重写无效进程([NotNull]AddFromTemplateArgs args)
{
身份证;
如果(args)已中止
||string.IsNullOrWhiteSpace(RuleFolderId)
||!Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database)
||!ID.TryParse(RuleFolderId,out ID))
{
返回;
}
Assert.HasAccess(args.Destination.Access.CanCreate(),“您没有在此处创建项目的权限”);
使用(new EventDisabler())//修复来自nexus的异常
{
var item=args.Destination.Database.Engines.DataEngine.AddFromTemplate(
args.ItemName,
args.TemplateId,
args.目的地,
args.NewId);
args.ProcessorItem=项目;
args.Result=项目;
}
var ruleContext=新的PipelineArgsRuleContext(args);
RuleManager.RunRules(ruleContext,id);
}
其他观察结果


只有在以编程方式从分支模板添加项时(从UI添加时从未发生),才会出现大约33%的错误。错误的确切位置似乎每次都在变化,我无法找到这种随机化的来源

如果将调试器附加到IIS进程,则应该能够单步执行处理程序并查看导致错误的原因。我需要查看事件处理程序的代码以确定触发异常的原因。Richard,错误发生在从Sitecore.Kernel.dll调用的Sitecore.Nexus.dll中,我不确定是否可以调试它们。我认为App.Client.Tasks.ItemEventHandler与错误有关,就好像我删除了它,错误就会消失一样。我已经用ItemEventHandler的源代码更新了这个问题。
        public override void Process([NotNull] AddFromTemplateArgs args)
        {
            ID id; 

            if (args.Aborted 
                || string.IsNullOrWhiteSpace(RuleFolderId) 
                || !Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database)
                || !ID.TryParse(RuleFolderId, out id))
            {
                return;
            }

            Assert.HasAccess(args.Destination.Access.CanCreate(), "You do not have permission to create items here.");

            // exception thrown from this call, which is a required call for this  
            //   processor, or else the item will not actually be created
            var item = args.Destination.Database.Engines.DataEngine.AddFromTemplate(
                args.ItemName,
                args.TemplateId,
                args.Destination,
                args.NewId);

            args.ProcessorItem = item;
            args.Result = item;

            var ruleContext = new PipelineArgsRuleContext<AddFromTemplateArgs>(args);

            RuleManager.RunRules(ruleContext, id);
        }
    public override void Process([NotNull] AddFromTemplateArgs args)
    {
        ID id; 

        if (args.Aborted 
            || string.IsNullOrWhiteSpace(RuleFolderId) 
            || !Settings.Rules.ItemEventHandlers.RulesSupported(args.Destination.Database)
            || !ID.TryParse(RuleFolderId, out id))
        {
            return;
        }

        Assert.HasAccess(args.Destination.Access.CanCreate(), "You do not have permission to create items here.");

        using (new EventDisabler()) // fixes the exception from nexus
        {
            var item = args.Destination.Database.Engines.DataEngine.AddFromTemplate(
                args.ItemName,
                args.TemplateId,
                args.Destination,
                args.NewId);

            args.ProcessorItem = item;
            args.Result = item;
        }

        var ruleContext = new PipelineArgsRuleContext<AddFromTemplateArgs>(args);

        RuleManager.RunRules(ruleContext, id);
    }