Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException occurs when trying to accept VersionAddedNotification via PowerShell in Sitecore #1331

Closed
mrvinaykj opened this issue May 6, 2024 · 1 comment
Assignees
Labels
area-commands Involves functions and cmdlets. improvement Extra sugar and spice.
Milestone

Comments

@mrvinaykj
Copy link

Expected Behavior

No exceptions should occur when accepting VersionAddedNotification via PowerShell in Sitecore.

Actual Behavior

NullReferenceException occurs when trying to accept VersionAddedNotification via PowerShell in Sitecore.
It happens for cloned items after creating a new numbered version for its master item.

Steps to Reproduce the Problem

Steps to reproduce:

  1. Create a master item - /sitecore/content/Home/Sample Item
  2. Clone master item - /sitecore/content/Home/Clones/Sample Item
  3. Add a numbered version for the master item
  4. Run the below PS script
$item = (Get-Item -Path "/sitecore/content/Home/Clones/Sample Item" -Language "en")
Write-Host $item.Uri
Write-Host "------------------------------"

$notifications = Get-ItemCloneNotification -Item $item

$notifications | % { Write-Host $_.Type $_.VersionUri}

foreach ($notification in $notifications)
{
if ($notification -ne $null)
{
if ($notification.Type -eq "VersionAddedNotification" `
-and $notification.Type -ne "FirstVersionAddedNotification")
{
Write-Host $notification.ItemUri

Receive-ItemCloneNotification -Notification $notification -Action Accept
}
}
}

Debugging the source code, we detected the exception occurs in VersionAddedNotification.Accept method
when trying to invoke this.SendMessage - see attached pictures

  • 1_VersionAddedNotification.Accept.jpg
    1_VersionAddedNotification Accept
  • 2_VersionAddedNotification.SendMessage.jpg
    2_VersionAddedNotification SendMessage
  • 3_ClientPage.jpg
    3_ClientPage

The reason for the issue is HttpContext.Current is null.

It is reproduced not steadily - after several attempts, it could be successfully accepted.
But, each failed attempt adds a new version for the cloned item.

AdamNaj added a commit that referenced this issue May 20, 2024
…dedNotification via PowerShell in Sitecore
@AdamNaj AdamNaj self-assigned this May 20, 2024
@AdamNaj AdamNaj added improvement Extra sugar and spice. area-commands Involves functions and cmdlets. labels May 20, 2024
@AdamNaj AdamNaj added this to the 8.0 milestone May 20, 2024
@AdamNaj
Copy link
Member

AdamNaj commented May 20, 2024

This one should be fixed but I have a feeling it's a lost cause... I don't think the notification for Field approval is going to be so easy to handle. unless we start taking over some of the "Accept" code. in some of the notifications.

@AdamNaj AdamNaj closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commands Involves functions and cmdlets. improvement Extra sugar and spice.
Projects
None yet
Development

No branches or pull requests

2 participants