PAL v2.4 / v2.5 bug with MS Charts SaveImage? - Help!

Jul 21, 2014 at 7:12 AM
Edited Jul 21, 2014 at 7:16 AM
Hi Clint, we have PAL v2.4 installed on 12 SQL servers (ranging from Dell to HP to IBM and all running Windows 2008 R2 SP1). All the servers are scheduled to generate a report everyday just after midnight. Randomly, the following error appears when they try to generate a report. The issue is driving us crazy!

Error below:
Exception calling "SaveImage" with "2" argument(s): "A generic error occurred i
n GDI+."
At C:\Program Files\PAL\PAL\PAL.ps1:1500 
Script arguments below:
Your locale is set to: English (Australia)
SCRIPT ARGUMENTS:
-Log C:\Scripts\PAL\Reports\Staging\PERFMON\CLST-CAN02SQL01-SQLServer2012-2014-
07-19_0-05-01.blg
-ThresholdFile C:\Program Files\PAL\PAL\SQLServer2012.xml
-Interval AUTO
-OutputDir C:\Scripts\PAL\Reports\Staging\PAL
-IsOutputHtml True
-HtmlOutputFileName PAL_ANALYSIS_[LogFileName].htm
-AllCounterStats False
-IsOutputXml False
-XmlOutputFileName PAL_ANALYSIS_[LogFileName].xml
-BeginTime 19/07/2014 7:00:00AM
-EndTime 19/07/2014 7:00:00PM
For example:

Monday
Server 1: Report generation Fail - SaveImage error
Server 2: Report generation Success
Server 3: Report generation Success
Server 4: Report generation Fail - SaveImage error

Tuesday
Server 1: Report generation Success
Server 2: Report generation Fail - SaveImage error
Server 3: Report generation Success
Server 4: Report generation Fail - SaveImage error

After a couple of Google searches it appears the issue is with the MS Chart component not having access to the output directory. Now the service account that the scheduled task is configured to use is a "Enterprise Admin", yes not good but we're desperate. We've tried many different accounts, including creating local accounts with admins rights and the error still randomly occurs. We upgraded a couple of servers to PAL 2.5, same issue again. So to confirm the account we're running the PAL script under has 1) Admin rights to the output folder and 2) The output folder actually exists, we added the following code from line 1500 in PAL.ps1
    Write-Host "#### Capturing directory information - start ####"
    Write-Host $sSaveFilePath
    split-path $sSaveFilePath -Parent
    $moo = split-path $sSaveFilePath -Parent | Test-Path
    $cow = split-path $sSaveFilePath -Parent
    Write-Host $cow
    if ($moo)
    {
    Write-Host "Path found - yay"
    Write-Host "---Permissions---"
    $perms = Get-Acl -Path $cow | Format-List AccessToString
    $perms
    Get-Acl -Path $cow | Format-List accessToString | Out-File -FilePath c:\temp\paloutputacl.txt -Append
    Write-Host "---Permissions---"
    }
    else
    {
    write-host "Path not found"
    }
    Write-Host "#### Capturing directory information - end ####"
Here is the output with the injected code:
[Started] Process % Privileged Time
    Time data (one time only)...Done
    Counter data for "sqlservr"...Done
    Auto analysis interval (one time only)...Done
    Quantized index (one time only)...Done
    Quantized time (one time only)...Done
    Generating Charts.#### Capturing directory information - start ####
C:\Scripts\PAL\Reports\Staging\PAL\PAL_ANALYSIS_CLST-CAN02SQL01-SQLServer2012-2014-07-19_0-05-01\Process_Percent_Privileged_Time0.png
C:\Scripts\PAL\Reports\Staging\PAL\PAL_ANALYSIS_CLST-CAN02SQL01-SQLServer2012-2014-07-19_0-05-01
Path found - yay
---Permissions---
AccessToString : PAC\s-palreports Allow  Modify, Synchronize
                 NT AUTHORITY\SYSTEM Allow  FullControl
                 BUILTIN\Administrators Allow  FullControl
                 BUILTIN\Users Allow  ReadAndExecute, Synchronize
                 BUILTIN\Users Allow  AppendData
                 BUILTIN\Users Allow  CreateFiles
                 CREATOR OWNER Allow  268435456
---Permissions---
#### Capturing directory information - end ####
WARNING: Please post errors or problems with this tool to the PAL web site 
located at http://www.codeplex.com/PAL with the following error message and a 
brief description of what you were trying to do. Thank you.
Exception calling "SaveImage" with "2" argument(s): "A generic error occurred i
n GDI+."
At C:\Program Files\PAL\PAL\PAL.ps1:1520 char:29
+     [Void] $oPALChart.SaveImage <<<< ($sSaveFilePath, $oPALChartImageFormat) 
   
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordE 
   xception
    + FullyQualifiedErrorId : DotNetMethodException
So from the output above you can see that the 1) s-palreports (the account the scheduled task runs under) has modify rights to the directory (well it would anyway since it's a enterprise admin) and 2) the directory does exist.

After further investigating I found someone using PAL v2.1.0 experiencing the same issue, https://pal.codeplex.com/workitem/22255, unfortunately they never got back to you.

I then came across the following page where they talk about the memory stream being closed too soon which causes the GDI+ SaveImage exception:

http://stackoverflow.com/questions/336387/image-save-throws-a-gdi-exception-because-the-memory-stream-is-closed

Not sure if that helps? but if you could point us in the right direction it would be greatly appreciated. We love PAL but it would be nice to have stable report generation.
Coordinator
Sep 8, 2014 at 11:33 PM
The SaveImage function most often fails when the output directory is too long. The SaveImage function is part of the Microsoft Chart Controls and is limited on the length of the path to the output file name. My guess is it is limited to 256 characters. As a work around, try using an Output Directory (passed into PAL.ps1) that is smaller.