Unexpected exception when completing task 'Analyze Files': Invalid number of analysis bands.

I'm getting weird error when trying to analyze files using PowerShell Toolkit:

Error: Unexpected exception when completing task 'Analyze Files': Invalid number of analysis bands.

Sdl.ProjectAutomation.Core.ProjectAutomationException: Unexpected exception when completing task 'Analyze Files': Invalid number of analysis bands. ---> Sdl.ProjectApi.ProjectApiException: Unexpected exception when completing task 'Analyze Files': Invalid number of analysis bands. ---> System.ArgumentException: Invalid number of analysis bands
   at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.SetAnalysisWordCounts(AnalysisContentProcessorX processor, ITranslatableFile translatableFile, WordCounts newWordCounts)
   at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.UpdateFileAnalysisStatistics(AnalysisContentProcessorX processor)
   at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.TaskComplete()
   at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.TaskComplete()
   --- End of inner exception stack trace ---
   at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.TaskComplete()
   at Sdl.ProjectApi.Implementation.AutomaticTaskExecuter.Execute()
   --- End of inner exception stack trace ---

It looks like some very weird bug in the API since the exception is thrown ONLY when running the task with displaying progress status... it does NOT occur when the same task is run without status event handler.

Here is the event handlers code.
Note that the same event handlers work PERFECTLY FINE with tasks like "Scan", "Convert to Translatable Format" or "Copy to Target Languages", i.e. I doubt that the event handlers are the actual problem.

function Write-TaskProgress {
    param(
    [Sdl.ProjectAutomation.FileBased.FileBasedProject] $Project,
    [Sdl.ProjectAutomation.Core.TaskStatusEventArgs] $ProgressEventArgs
    )

    $Percent = $ProgressEventArgs.PercentComplete
    $Status = $ProgressEventArgs.Status

    Write-Host "  $Percent%    $Status`r" -NoNewLine

}

function Write-TaskMessage {
    param(
    [Sdl.ProjectAutomation.FileBased.FileBasedProject] $Project,
    [Sdl.ProjectAutomation.Core.TaskMessageEventArgs] $MessageEventArgs
    )

    $Message = $MessageEventArgs.Message

    Write-Host "`n$($Message.Level): $($Message.Message)" -ForegroundColor DarkYellow
    if ($($Message.Exception) -ne $null) {Write-Host "$($Message.Exception)" -ForegroundColor Magenta}
}

And this is the code which executes the task and causes the exception:

$Task = [Sdl.ProjectAutomation.Core.AutomaticTaskTemplateIds]::AnalyzeFiles
$Project.RunAutomaticTask($TargetFilesGuids, $Task, ${function:Write-TaskProgress}, ${function:Write-TaskMessage})

Weird thing is that calling the RunAutomaticTask function either using the overload without event handlers, or using NULL status event handler, runs just fine and task is executed correctly (and this also answers a question if the analysis bands are actually defined correctly in the project - YES, they are).
So the two following calls run the task successfully:

$Project.RunAutomaticTask($TargetFilesGuids, $Task)
$Project.RunAutomaticTask($TargetFilesGuids, $Task, $null, ${function:Write-TaskMessage})

I see only one explanation of this weird behavior - that there is something rotten in the API...
And I want to know how fast will it be fixed, so that the analysis task (and any other possibly affected task) can be actually used via API including the status progress...

Parents Reply
  • Hi Evzen,

    I had the Invalid number of analysis band on one language, and the "AnalysisStatistics" element was under the "LanguageDirection" element. I removed it, and it does work now, since that information is just coming from some statistics, but not necessary for Studio to work.
    You can probably remove the whole "AnalysisStatistics" element from "LanguageFile" (or even from everywhere in the sdlproj file) without affecting Studio functionality, since this is just optional.
    I guess if there is no more information on statistics, then the error should banish!

    Best,
    Saul Ruiz Calleja
Children