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 {
    [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 {
    [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...

  • Can this get some SDL developer's attention, please?! It's really extremely annoying to not be able to use batch tasks status progress in automation :(

    According to my further investigation, the "Invalid number of analysis bands" seems to be just secondary error caused by the real root problem - that the batch task is not executed at all, but it's still reported as 100% completed.
    So, IMHO, the subsequent procedures (UpdateFileAnalysisStatistics and SetAnalysisWordCounts) try to update the analysis stats, but since the analysis was probably not even properly initialized, neither actually performed, it throws the exception.

    Running other tasks like Pretranslate or PerfectMatch shows the same behavior - the task is not executed at all, but its Status is still set to "Completed", so it looks like everything is just fine :-\. These tasks do not throw any error, IMHO basically just because there are not any subsequent internal procedures which would fail like in the case of Analysis task.

    Example of running Pretranslate with the progress event handler - it finished in 0.3 seconds, which is nonsense... plus, the files were NOT pretranslated.

    The same Pretranslate without progress event handler - it took 67 seconds... and the files ARE pretranslated.

    Additional info: here is what the created project shows when opened in Studio - task status is Completed, but all its files show "Not processed"... and of course, no report was created.

    Additional info 2: Weirdly enough, running TranslationCount task works just fine with the progress event handler! :-O
    The same goes for tasks Scan, ConvertToTranslatableFormat and CopyToTargetLanguages (the last one is actually even seen on the screenshots)

    So this pretty clearly shows that the event handler itself is NOT the problem...

  • Hello Mr. Polenka,

    I have tried running our integration tests for the AnalyzeFiles operation in the context that you specified (without the progress event handler) and I cannot reproduce the behavior that you described.
    You mentioned that you are creating a new project from code so that's where our testing environments differ (our tests load existing projects from the hard drive). Could you please give me the project creation code and any files that you are using for creating the project when getting this error?

    Best regards,
    Bogdan Petrovici
  • Hi Bogdan, you can find the code right here in this thread, in the original post.

    More code and more context can be found in the STraSAK tool linked below. Although the thread is more than 2 years old, the code did not change (much) since and you can find the implemented workaround there in the "ProjectHelper" module:

    This means that you should be able to reproduce the problem using the STraSAK toolkit - just remove this workaround, i.e. remove the condition and use just the piece in the "else" branch (i.e. the one including the "Write-TaskProgress" function call).
    And then create new project using the New-Project command including -PreTranslate and/or -Analyze switch.

Reply Children
No Data