3

Closed

Unable to save Options

description

I get this error when clicking the save button in Options.

looks like the Options.xml gets corrupt?
this is happending even with a new download from this site.


Cannot index into a null array.
At C:\Users\v-igoza\Desktop\PoshPAIG_2_1_5\Options.ps1:82 char:9
  • $Optionshash['MaxRebootJobs'] = $MaxRebootJobs_txtbx.Text
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\v-igoza\Desktop\PoshPAIG_2_1_5\Options.ps1:89 char:9
  • $Optionshash['MaxJobs'] = $MaxJobs_txtBx.Text
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\v-igoza\Desktop\PoshPAIG_2_1_5\Options.ps1:96 char:9
  • $Optionshash['ReportPath'] = $ReportPath_txtbx.Text
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\v-igoza\Desktop\PoshPAIG_2_1_5\Start-PoshPAIG.ps1:66 char:9
  • $Global:maxConcurrentJobs = $Optionshash['MaxJobs']
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\v-igoza\Desktop\PoshPAIG_2_1_5\Start-PoshPAIG.ps1:67 char:9
  • $Global:MaxRebootJobs = $Optionshash['MaxRebootJobs']
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\Users\v-igoza\Desktop\PoshPAIG_2_1_5\Start-PoshPAIG.ps1:68 char:13
  • If ($Optionshash['ReportPath']) {
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray
Closed Jun 6, 2016 at 2:52 PM by boeprox

comments

xoring wrote May 18, 2014 at 3:52 AM

It looks like this issue is caused by not having the options.xml file loaded within the scope of the $Save_btn.Add_Click event. So when you go to save it, $Optionshash is null and it can't write anything to MaxRebootJobs, MaxJobs, and ReportPath. Then it saves the options.xml with the null $Optionshash array inserted where those values should be. I resolved it by having it import the options.xml at the top of the save button action.
 $Optionshash = Import-Clixml -Path (Join-Path $Path 'options.xml')
You could also do this:
#Save Button
$Save_btn.Add_Click({
    $i = 0

    #Validate option data is valid
    If ($MaxRebootJobs_txtbx.Text -notmatch "^\d+$") {
        $MaxRebootJobs_txtbx.ForeGround = 'Red'
        $i++
    } Else {
        $MaxRebootJobs_txtbx.Foreground = 'Black'
        $MaxRebootJobs = $MaxRebootJobs_txtbx.Text
    }
    If ($MaxJobs_txtBx.Text -notmatch "^\d+$") {
        $MaxJobs_txtBx.ForeGround = 'Red'
        $i++
    } Else {
        $MaxJobs_txtBx.Foreground = 'Black'
        $MaxJobs = $MaxJobs_txtBx.Text
    }    
    If ($ReportPath_txtbx.Text -notmatch '\w:\\[a-zA-Z0-9\\-_]*') {
        $ReportPath_txtbx.ForeGround = 'Red'
        $i++
    } Else {
        $ReportPath_txtbx.Foreground = 'Black'
        $ReportPath = $ReportPath_txtbx.Text
    }      
    #Save update options to XML file
    If ($i -eq 0) 
    {
         $optionshash = @{
            MaxJobs = $MaxJobs
            MaxRebootJobs = $MaxRebootJobs
            ReportPath = $ReportPath
        }
        $optionshash | Export-Clixml -Path (Join-Path $pwd 'options.xml') -Force
        $Window.Close()
    }
})

jvgonzalez wrote Jun 13, 2014 at 8:19 PM

What I did was to open options so it can create the options.xml in the folder. Dont save any settings and close POSHAIG. Then modify the XML to whatever setting I want and save and reopen.

boeprox wrote Sep 29, 2014 at 8:00 PM

This will be fixed in 2.1.6