sitecore - Server Error "Object reference not set to an instance of an object" after insert from branch -
everything works correctly after sitecore update 7.0 7.2 see following server error when creating site branch
[nullreferenceexception: object reference not set instance of 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 target of 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 a site creates correctly , see no problems there.
as far see error occurs in item:addmaster command:
<command name="item:addmaster" type="sitecore.shell.framework.commands.addmaster,sitecore.kernel" /> i have tried decompile sitecore.nexus library without success. after of hours of investigation found error disappears if turn off custom event handler
<event name="item:created"> <handler type="app.client.tasks.itemeventhandler, app.client" method="onitemcreated" /> </event> the handler responsible auto mapping configuration settings in new site created branch. technically there item in branch template called mapper , works trigger. last item in branch tree. when admin adds site branch, event handler checks mapper created (in other words site created), runs auto mapping functionality , deletes trigger.
if omit checks, handler looks like
new itemmappingmanager(contextitem, database.getdatabase("master").items[id.parse(mappingconfigurationitemid)]).execute(); // delete trigger item once branch has been created , mapping done using (new securitydisabler()) { contextitem.delete(); } looks changed in sitecore's event model have lack of knowledge here.
try wrapping calls sitecore.data.engines.dataengine.addfromtemplate or calls making add item eventdisabler. because exception being thrown in nexus, it's difficult exact cause of issue is.
when experienced similar issue, had theory there may have been eventing firing , causing exceptions. error did not occur, , difficult find cause of error since being thrown in nexus. while investigating , debugging best (deobfuscated, decompiled , read through , debugged nexus), found there several api calls being made raise events (e.g. addversion, addmaster, etc.). considered theory confirmed when exception disappeared after wrapped code in eventdisabler.
my similar experience
i experienced same issue sitecore 8.1.2. difference between code , code in op leveraging new (i believe newer op) itemprovider via processor have added addfromtemplate pipeline.
the below processor added. use processor run rules, , receiving exact same error, until wrapped call sitecore.data.engines.dataengine.addfromtemplate (must called or else item never gets created) in eventdisabler.
processor before fix
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 not have permission create items here."); // exception thrown call, required call // processor, or else item not 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); } processor fix
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 not have permission create items here."); using (new eventdisabler()) // fixes exception 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); } additional observations
the error experienced 33% of time , when adding item branch template programmatically (never occurred when adding ui). exact location of error appeared change each time, , not able find source of randomization.
Comments
Post a Comment