Trados Sudio 2024 API FieTypeId is null for HTML files

The FileTypeId is null after scanning in Trados 2024 when using the API. The FileTypeId cannot be assigned, it is read only
The problem persits even if create new FileTypeId for HTM with File > Options. 

It is not possible to assign it.
Screenshot of code with a debug tooltip showing properties of 'oArrProjectFile0' with 'FileTypeId' highlighted, indicating a null value for the 'FileTypeId' property.Screenshot of code with an exception handling block highlighted, showing a condition where 'FileTypeId' is null, triggering an exception 'FileTypeId is null for' with the file extension.

Please help. It is an urgent problem. We cannot process HTML files.

Regards
Martin Bächtold



Generated Image Alt-Text
[edited by: RWS Community AI at 2:25 PM (GMT 1) on 11 Sep 2024]
  •  

    Just an update to let you know that we are looking at this and will respond as soon as we have something appropriate to share.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Thank you for bringing this to our attention. Our development team will review it in the context of our ongoing projects and priorities. Your understanding and patience as we assess this matter is appreciated. We have recorded the issue in our tracking system under the reference number CRQ-39749
  • Hello   ,

    Thank you for bringing this issue to our attention.

    We have been able to reproduce the problem you described regarding the FileTypeId being null after scanning in Trados Studio 2024 when using the Project Automation API. Our investigation indicates that this issue occurs when the HTML settings are disabled in the File Type Configuration.

    To resolve this issue, please follow these steps:

    1. Go to Project Settings > File Type.
    2. Ensure that the HTML file type is enabled.   

    If the HTML file type is disabled, Trados Studio will attempt to mark the file as a reference and will not perform the conversion, which is likely causing the issue you're experiencing.

    If you do not see HTML listed, you can add it by navigating to Project Settings > File Type > New > HTML, then follow the wizard instructions to complete the setup.

    For our testing, we have used samples from the Trados PowerShell Toolkit and the SDL Community Code Samples to reproduce and investigate the issue.

    Please let us know if enabling or adding the HTML file type resolves the problem or if you need further assistance.

    Best Regards,

    Alexandru Florescu

  • When I call the File Types form the API, HTML5 is missing. When I check with Trados Studio HTML5 is present.
    Studio has approx 35 Files Types, API has only 21.

    Screenshot of Studio Developers Q&A software showing File Types options. A red box highlights HTML5 in the list and text annotations indicate 'In the API 21 Files Types are available and in Studio 35!!! HTML5 is among the 21!' and 'NOT HERE'.

    Screenshot of code snippet from Studio Developers Q&A. The code is for a method called cmd_ShowFileTypes_Click, which iterates through AutoLoadedFileTypes and shows them using ShowLog method.

    It does not resolve the problem! 

    Regards 
    Martin




    Generated Image Alt-Text
    [edited by: RWS Community AI at 8:20 AM (GMT 1) on 15 Sep 2024]
  •   

    I can't tell from these snippets and I may be on the wrong track completely, but are you sure that you are calling the project template you are comparing this to? 

    fyi:

       

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Hi , can you provide us with a copy of your source code project?

    We have confirmed that this is working as expected from sample projects, so reviewing your source code migth help us understand better what is causing the issue from your project.

    Can you tell me what you have set as the output path of your project, e.g. where are you building & running your binaries, exe's?

    Please let us know.

  •  

    Hi everbody,

    The code for my API has been running since 2015 and has worked with all versions except the new 2024 version. The output path is not the issue.
    The problem is that the FileTypeId is null for HTML files, and since it is set internally, I cannot assign it in my code.

    // Sdl.ProjectAutomation.Core, Version=18.0.0.0, Culture=neutral,
    // Sdl.ProjectAutomation.Core.ProjectFile
    public string FileTypeId { get; internal set; }

    To clarify the issue again:

    //Create a Word file...
    string strFilePath_TestFile_Docx = Path.Combine(strDirPath_PackagesCreateTmp_TestTradosProjectCreation, "TestTrados.docx");
    WordApplication oWordApplication = new WordApplication();
    var oWordDoc = oWordApplication.Documents.Open(strFilePath_TestFile_Docx);
    Paragraph para = oWordDoc.Content.Paragraphs.Add();
    para.Range.Text = "This is a test text added programmatically.";
    para.Range.InsertParagraphAfter();
    oWordDoc.SaveAs2(strFilePath_TestFile_Docx);

    //Create a HTML file
    string strFilePath_TestFile_Html = Path.Combine(strDirPath_PackagesCreateTmp_TestTradosProjectCreation, "TestTrados.html");
    string strHtmlContent = @"
    <!DOCTYPE html>
    <html lang='en-GB'>
    <head>
    <meta charset='UTF-8'>
    <title>Minimal HTML</title>
    </head>
    <body>
    <h1>Hello, World!</h1>
    <p>This is a minimal HTML page created in C#.</p>
    </body>
    </html>";
    File.WriteAllText(strFilePath_TestFile_Html, strHtmlContent);


    //Create Project info and check if the source language is assigned
    SdlProjectInfo oProjectInfo = CheckProjectCreation_GetProjectInfo(strDirPath_PackagesCreateTmp);
    if (Directory.Exists(oProjectInfo.LocalProjectFolder))
    {
         TTN_FunUtil.CleanDirectory(oProjectInfo.LocalProjectFolder);
    }
    TT_oTTN_Show.ShowLog_wo_Time("Project source language: " + oProjectInfo.SourceLanguage);


    //Add the docx and the html files
    string[] strArrFiles = CheckProjectCreation_AddProjectFiles(strDirPath_PackagesCreateTmp_TestTradosProjectCreation);
    SdlProjectFile[] oArrSdlProjectFile = oFileBasedProject.AddFiles(strArrFiles);

    //Scan Files
    Guid[] oIds = oFileBasedProject.GetSourceLanguageFiles().GetIds();
    foreach (var oGuid in oIds)
    {
        List<SdlTaskStatusEventArgs> taskStatusEventArgsList_Scan = new List<SdlTaskStatusEventArgs>();
        List<SdlMessageEventArgs> messageEventArgsList_Scan = new List<SdlMessageEventArgs>();

        List<Guid> oIdList = new List<Guid> { oGuid };
        Guid[] oArrId = oIdList.ToArray();
        SdlAutomaticTask scanFiles = oFileBasedProject.RunAutomaticTask(
            oArrId,
            SdlAutomaticTaskTemplateIds.Scan,
            (sender, taskStatusArgs) => taskStatusEventArgsList_Scan.Add(taskStatusArgs),
          (sender, messageArgs) => messageEventArgsList_Scan.Add(messageArgs));
          if (scanFiles.Status != SdlTaskStatus.Completed)
              throw new Exception("Failed to scan files");
          TT_oTTN_Show.ShowLog_wo_Time(taskStatusEventArgsList_Scan[taskStatusEventArgsList_Scan.Count - 1].StatusMessage);
          foreach (var oMessage in messageEventArgsList_Scan)
          {
               TT_oTTN_Show.ShowLog_wo_Time(oMessage.Message.Message);
          }
    }

    //Check scanned files
    SdlProjectFile[] oArrSdlProjectFileSource_Check = oFileBasedProject.GetSourceLanguageFiles();
    foreach (SdlProjectFile oSdlProjectFileSource in oArrSdlProjectFileSource_Check)
    {
         if (oSdlProjectFileSource.FileTypeId == null)
         {
               string strExt = Path.GetExtension(oSdlProjectFileSource.Name);
               TT_oTTN_Show.ShowLog_wo_Time("Warning FileTypeId is null for " + strExt + " after run SdlAutomaticTaskTemplateIds.Scan");
               TT_oTTN_Show.ShowLog_wo_Time("Warning The Role was set to " + oSdlProjectFileSource.Role);
               TT_oTTN_Show.ShowLog_wo_Time("Warning The Language is " + oSdlProjectFileSource.Language);
         }
    }

    Warning The Language is en-GB
    Warning The Role was set to Reference
    Warning FileTypeId is null for .html after run SdlAutomaticTaskTemplateIds.Scan
    Scannig file \\TTN27\TTN27_D$\TtnD\Cat\PackagesCreateTmp\Trados_Test_Project\en-GB\TestTrados.html failed. Setting file role to reference. Exception message System.ArgumentNullException: Value cannot be null.
    at Sdl.LanguagePlatform.Core.CultureInfoExtensions.AreCompatible(CultureInfo c1, CultureInfo c2)
    at Sdl.ProjectApi.AutomaticTasks.Tasks.Scan.LanguageResolver.CheckSourceLanguage(SniffInfo sniffInfo, Language projectSourceLanguage, Action`2 reportMessage)
    at Sdl.ProjectApi.AutomaticTasks.Scan.ScanTask.ProcessFile(IExecutingTaskFile executingTaskFile).
    Project source language: en-GB

    The .docx files are working perfectly, but processing HTML files results in a critical error.
    If no solution is proposed, I will create a standalone application to isolate the issue with the code shown above.

    This is an urgent problem. We are dealing with natural hazards (storms, floods), and our inability to process HTML files is impacting our operations.

    Thanks in advance for your help.
    Regards
    Martin





  • Hi  , so I guess that's a no to accessing your source project and no to telling us the output path?

    The FileTypeId is internal as it needs to be set by the studio environment; the fact that it's null might indicate that your code project can't locate the dependencies from the API's that you have referenced.

    It's really hard to understand from your example. 

    What I recommend is that we provide you with a sample code project, that we confirm working, so far as it will automate creating a project with a HTML file.  You can review this sample project and confirm it also works from your environment. WDYT?

    We will followup once we get an opporunity to work on this.

  •  

    Hi Patrick

    output path:

    C:\Program Files (x86)\Trados\Trados Studio\Studio18\

    Screenshot showing an output path field with a directory path to Trados Studio 18 within Program Files (x86) on a Windows system.


    In Studio HTML 5 is activated and on the top:

    Screenshot of Trados Studio settings with the File Types section highlighted, showing HTML 5 as an enabled file type among others.



    The File Types can be loaded and HTML5 is enabled
    Here is the code:

    Screenshot of code in an IDE, checking if HTML 5 file type definition is enabled in Trados Studio and logging the result.

    This code produces this output:
    Screenshot of Trados Studio's File Types output log indicating HTML 5 is enabled and the file type is found with version 5.2.0.0.

    The sample code that I found on your site is already part of our programm and I would not help. In order to test each function, we developped a hohle workbench.   

    Screenshot of Trados Studio's server tools with 'Run Sample Code' button highlighted, indicating a function to execute sample code.

    I try to extract the code now and I will send you my sample code by mail.

    Regards
    Martin



    Generated Image Alt-Text
    [edited by: RWS Community AI at 7:51 AM (GMT 1) on 19 Sep 2024]
  • Hi Patrick

    I have created  a standalone application in order to reproduce the strange bug,

    You can download it here:

    https://we.tl/t-BEVvippMgy

    Screenshot of an application error log with multiple entries. Errors include 'AutomaticTaskExecutor Unexpected exception', 'ProjectPackageCreation failed', and 'Object reference not set to an instance of an object'. A red arrow points to one of the error messages.

    Please let me know if you need other infromation.

    R.
    Martin



    Generated Image Alt-Text
    [edited by: RWS Community AI at 11:43 PM (GMT 1) on 19 Sep 2024]