1

Situation

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

Problem

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)

Observations

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">
    <authorization>
        <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"/>
    </authorization>
</restfulv2>

Additionally this only shows up on the first call

Question

Why am I receiving this exception?

2
  • Problem may be addressed with this issue: github.com/SitecorePowerShell/Console/issues/997 Commented May 6, 2018 at 3:03
  • @MichaelWest you can turn your comment into an answer so I can accept it :) Commented Aug 9, 2018 at 7:57

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.