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]
Parents
  • 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

Reply
  • 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

Children
  • 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]
  • Hi  , we have confirmed this is a bug against 2024 and escalated it to development team.  Thank you for raising this and providing the sample code to reproduce.

    I don't have a workaround for this atm, but will circle back to you once I know more. 

  • Hi  ,

    The development team have identified a discrepancy in the version of the `System.Text.Encoding.CodePages.dll` that is released with Trados Studio 2024. We understand the impact this has on your solution and appreciate your patience as we work towards a resolution.

    The filters affected by the version include Bilingual Excel, HTML, XLIFF, and XML. The problem arises because these filters currently depend on version 7.0.0.0, while Studio operates on version 8.0.0.0. This version mismatch explains why the problem does not reproduce in the Trados Studio desktop application, as it handles dependencies differently.

    We anticipate that a solution will be implemented in CU2 onwards.

    In the meantime, we have identified the following workarounds:

    Workaround 1:

    Add a dependency binding redirect to your project in the App.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
      </startup>
      <runtime>
        <NetFx40_PInvokeStackResilience enabled="1" />
        <legacyCorruptedStateExceptionsPolicy enabled="true" />
        <ThrowUnobservedTaskException enabled="true" />
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    Workaround 2:

    You can manually download the `System.Text.Encoding.CodePages.dll` version 7.0.0.0 from NuGet and add it as a project reference to your application. Compiling this version with your Project Automation solution should resolve the reported issue. However, please note the following consequences:

    1. Studio Compatibility: Trados Studio 2024 relies on version 8.0.0.0, so using version 7.0.0.0 may affect scan tasks within the Trados Studio desktop application.

    2. Version Switching: Should you need to revert to version 8.0.0.0, please keep a backup of the original version of `System.Text.Encoding.CodePages.dll` and switch between versions, as necessary.

    We appreciate your understanding and remain committed to enhancing our software. If you have further questions or need assistance with the workaround, please feel free to reach out.