Console icon indicating copy to clipboard operation
Console copied to clipboard

Sitecore 10.2 - Type initializer exception when executing script via WebAPI

Open larionovadaria opened this issue 2 years ago • 5 comments

Expected Behavior

restfulv2 service works as expected right after deployment.

Actual Behavior

Similar to: https://github.com/SitecorePowerShell/Console/issues/982

  • Couldn't reproduce locally, only on Azure.
  • Fix described here https://github.com/SitecorePowerShell/Console/issues/982#issuecomment-389877686 didn't help, but the issue completely disappears if you manually restart WebApp once again after deployment, which makes me think something happens during initialization.
  • Issue began to happen only after remoting restfulv2 service was enabled. Sitecore Powershell itself worked without any issues on current version and previous ones.

Setup

Sitecore PowerShell Extensions 6.3.0.17327 Sitecore 10.2 Azure WebApp hosting

Steps to Reproduce the Problem

Steps to reproduce are similar to: https://github.com/SitecorePowerShell/Console/issues/982

larionovadaria avatar Nov 28 '23 12:11 larionovadaria

Is there something you're using with that endpoint that could be shifted over to the SPE Remoting endpoint?

michaellwest avatar Nov 28 '23 14:11 michaellwest

I think technically we could use SPE Remoting, but chose WebAPI instead to restrict running any script, and run only ones that we have predefined. Are you saying that we need to try to move to SPE Remoting and see if issue persists?

larionovadaria avatar Nov 28 '23 15:11 larionovadaria

I'm curious if running the scripts through SPE Remoting encounters the same initialization error.

Can you try something like this with SPE Remoting (and restfulv2 disabled)?

Import-Module -Name SPE
$session = New-ScriptSession -Username admin -Password b -ConnectionUri https://remotesitecore
Invoke-RemoteScript -Session $session -ScriptBlock {
        # Your script
        # or Get-Item -Path "your-script" | Invoke-Script
}
Stop-ScriptSession -Session $session

michaellwest avatar Nov 28 '23 15:11 michaellwest

The issue I described happens from time to time after deployment, locally it was never a problem. I'll try to do what you proposed, will monitor WebApp for a while and return back. Thank you.

larionovadaria avatar Nov 28 '23 15:11 larionovadaria