SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

Output_DataReady - output.Read() can return null even when output.Count > 0 #66

Closed Azkel closed 5 years ago

Azkel commented 5 years ago

Hello,

I tried to run a following PowerShell script (based on following code from Stack Overflow):

$hashString = "SOME_EXISTING_CERT_HASH"

$bind = Get-WebBinding -Name "Test" -Protocol "https"
$bind.AddSslCertificate($hashString, "my")

based on following task:

Task("Set-Certificate")
    .Does(() => 
{
    StartPowershellFile(@"SetCertificate.ps1");
});

Unfortunatelly I receive following error after running this task:

An error occurred when executing task 'Set-Certificate'. Error: One or more errors occurred. Object reference not set to an instance of an object.

This error is caused by Output_DataReady event - after AddSslCertificate command output.Count is greater than zero, but output.Read() returns null, which later turns into NullReferenceException during Debug.Log call at the end of the while loop. What's more interesting, this also causes PowerShell script to stop running.

After I've added another null check at outputItem, everything works properly and the end-result of the PowerShell script is visible in IIS.