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

15 Replies Latest Replies: 16 Nov 2017 2:31 PM by Andrew Jameson < 1   2   3  >

15 Replies

  • In reply to Saul Ruiz-Calleja:

    FWIW, , can you be more specific where exactly should the "AnalysisStatistics" element appear?
    As you can see on the screenshot below, my project does NOT contain such element (and I don't remember ever seeing any such element under "LanguageDirection" at all)...
    The only "AnalysisStatistics" element I see in the prject file is under each source "LanguageFile"...

  • In reply to Evzen Polenka:

    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
  • In reply to Saul Ruiz-Calleja:

    Hmmm, nevermind... That's not really useful.
    As I said, the project is being programmatically created as new from scratch, i.e. there is no analysis stats at all, since the entire project is only about to be analyzed yet... in the same process of creating the project... so there is no projecrt file at all yet, as it's all just in memory and still being created.

    All I know is that it's really very annoying that all the years-old error reports are completely IGNORED by SDL :(
  • In reply to Evzen Polenka:


    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
  • In reply to 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:

    EDIT:
    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.

< 1   2   3  >
Related