I'm trying to use the SPE Web API to call a simple script to publish 1 single item from gulp (in SXA Theme). The script URL call looks like this:

/-/script/v2/master/PublishItem?user=mypersonaluser&password=xxx&itemPath=/sitecore/media library/Themes/Portal/sass/main


When the call executes I receive a 500 error response with the following stacktrace:

15648 2018:04:13 16:46:48 ERROR Application error.
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: mscorlib
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Cognifide.PowerShell.Core.Settings.Authorization.ServiceAuthorizationManager.GetServiceAuthorizationInfo(String serviceName)
   at Cognifide.PowerShell.Core.Settings.Authorization.ServiceAuthorizationManager.IsUserAuthorized(String serviceName, String userName)
   at Cognifide.PowerShell.Console.Services.RemoteScriptCall.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


On request of Adam I already checked my showconfig.aspx and the section for my restfulv2 looks like this:

<restfulv2 requireSecureConnection="false" patch:source="Gulp.config" enabled="true">
        <add Permission="Allow" IdentityType="Role" Identity="sitecore\PowerShell Extensions Remoting"/>
        <add name="AdminRule" Permission="Allow" IdentityType="Role" Identity="sitecore\IsAdministrator" patch:source="Gulp.config"/>
        <!--add Permission="Allow" IdentityType="User" Identity="extranet\Anonymous" /-->
        <add Permission="Allow" IdentityType="User" Identity="sitecore\admin"/>

Additionally this only shows up on the first call


Why am I receiving this exception?


Potential fix scheduled for release with SPE 5.0.

There are appears to be a concurrency issue in SPE that may be addressed with issue 997.

Example: The following warms up the Sitecore instance and then immediately invokes the Web API. I used the following script to duplicate the error.

Invoke-WebRequest -UseBasicParsing -Uri "http://sc827/sitecore/service/keepalive.aspx" | Select-Object -ExpandProperty StatusDescription

$jobs = [System.Collections.ArrayList]@()
foreach($index in 1..5) {
    $job = Start-Job -ScriptBlock {
        $url = "http://sc827/-/script/v2/master/DoSomething?user=admin&password=b"
        Invoke-WebRequest -UseBasicParsing -Uri $url | Select-Object -ExpandProperty Content

    $jobs.Add($job) > $null

$jobs | Wait-Job
$jobs | Receive-Job

Note: The proposed fix converts a dictionary into a ConcurrentDictionary.

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.