5

I have implemented Auto-accepting changes for cloned items by following this Sitecore Knowledge-base article

However I get below error when adding new version from some translation services module working as Sitecore Agent:

Message-Object reference not set to an instance of an object.
Stack-   at Sitecore.Web.UI.Sheer.ClientPage..ctor()
   at Sitecore.Context.get_ClientPage()
   at Sitecore.Data.Clones.FirstVersionAddedNotification.Accept(Item item)
   at Sitecore.Data.Managers.NotificationManager.DataEngine_AddedVersion(Object sender, ExecutedEventArgs`1 e)
   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   at Sitecore.Data.Engines.EngineCommand`2.RaiseEvent[TArgs](EventHandler`1 handlers, Func`2 argsCreator)
   at Sitecore.Data.Engines.DataCommands.AddVersionCommand.Executed()
   at Sitecore.Data.Engines.EngineCommand`2.Execute()
   at Sitecore.Data.Engines.DataEngine.AddVersion(Item item)
   at Sitecore.Data.Managers.ItemProvider.AddVersion(Item item, SecurityCheck securityCheck)

Main code snippet:

private bool ShouldAutomaticallyAcceptChanges(Notification notification)
{             
  //Accepting notifications based on the setting value
  return Settings.GetBoolSetting("Cloning.AcceptChangesAutomatically", false);

  //Accepting notifications of the specific type
  //return notification is VersionAddedNotification;
}

The article has mentioned,

Implement the ShouldAutomaticallyAcceptChanges method according to your requirements. For example, you may accept all notifications based on your custom web.config setting, or you can check for notifications of a specific type, e.g. VersionAddedNotification

So Auto Accepting the VersionAddedNotication fails with above error.

How we can achieve this without error? Or may be there something else that I'm missing?

This is Sitecore 7.5 update-2

  • I don't event see your custom method in the stack trace of the exception that you posted. Are you sure you have followed all the steps from the KB article? – Andrey Bobrov Oct 27 '16 at 0:14
  • Yes it's not there in stack trace but if I disable the config having this patch the error disappears. – Harsh Baid Oct 27 '16 at 5:34
2

I think this is a bug with Sitecore.

If you look more closely at their documentation you can see that in their sample code they have a TryCatch that expects a NullReferenceException:

        if (this.ShouldAutomaticallyAcceptChanges(notification))
        {
            try
            {
                notification.Accept(ItemManager.GetItem(notification.Uri.ItemID,
                notification.Uri.Language, notification.Uri.Version,
                Database.GetDatabase(notification.Uri.DatabaseName)));
            }
            catch (NullReferenceException ex)
            { }
        }

Interesting that they would put that specific exception as an example... as if they knew ahead of time it's very likely that call to notification.Accept() will throw that type of error. Hate to to say it, as I don't think swallowing that type of exception is a good solution, but it is the only solution for now.

I'm guessing Sheer UI is looking for something inside that Item object you are passing and not finding it. That object is huge so it could be anything. Sitecore needs to fix this issue as it's still present in 8.2 as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.