Console
Console copied to clipboard
Sitecore 10.2 - Type initializer exception when executing script via WebAPI
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
Is there something you're using with that endpoint that could be shifted over to the SPE Remoting endpoint?
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?
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
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.