API: Failed to create an instance of translation provider deepltranslationprovider

I am currently using v4.8.25 of the plug-in, and I am still having issues when executing the Analyze and Pre-translate tasks from the API whenever my project template includes a Deepl MT provider. Could you please confirm from which version are this issues fixed?

For Analyze I have the same exception as Tamas above:

Unexpected exception when initializing task 'Analyze Files': Failed to create an instance of translation provider 'deepltranslationprovider:///?formality=Default&sendPlain=False'..

For Pre-translate I have the exception:

Unexpected exception when configuring file multiFileConverter for task 'Pre-translate Files': Failed to create an instance of translation provider 'deepltranslationprovider:///?formality=Default&sendPlain=False'..

My issue seems related to community.rws.com/.../deepl-plugin-crash-when-running-automatic-tasks-programatically

Thank you very much for your valuable support.

Kind regards,

Alejandroi

  • Stack trace:

    ProjectFileId :
    Source        : AutomaticTaskExecuter
    Message       : Unexpected exception when initializing task 'Analyze Files': Failed to create an instance of translation provider
                    'deepltranslationprovider:///?formality=Default&sendPlain=False'..
    Level         : Error
    Exception     : Sdl.ProjectAutomation.Core.ProjectAutomationException: Unexpected exception when initializing task 'Analyze Files': Failed to create an instance of translation provider
                    'deepltranslationprovider:///?formality=Default&sendPlain=False'.. ---> Sdl.ProjectApi.ProjectApiException: Unexpected exception when initializing task 'Analyze Files':
                    Failed to create an instance of translation provider 'deepltranslationprovider:///?formality=Default&sendPlain=False'.. --->
                    Sdl.ProjectAutomation.Core.ProjectAutomationException: Failed to create an instance of translation provider
                    'deepltranslationprovider:///?formality=Default&sendPlain=False'. ---> System.TypeInitializationException: The type initializer for
                    'Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'NLog,
                    Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies. The system cannot find the file specified.
                       at Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter..cctor()
                       --- End of inner exception stack trace ---
                       at Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter..ctor(String key, Formality formality)
                       at Sdl.Community.DeepLMTProvider.Studio.DeepLMtTranslationProviderFactory.CreateTranslationProvider(Uri translationProviderUri, String translationProviderState,
                    ITranslationProviderCredentialStore credentialStore)
                       at Sdl.LanguagePlatform.TranslationMemoryApi.TranslationProviderManager.CreateTranslationProvider(Uri translationProviderUri, String translationProviderState,
                    ITranslationProviderCredentialStore credentialStore)
                       at Sdl.ProjectApi.TranslationProviderCache.CreateTranslationProvider(Uri translationProviderUri, String translationProviderState, ITranslationProviderCredentialStore
                    credentialStore)
                       at Sdl.ProjectApi.TranslationProviderCache.GetTranslationProvider(Uri translationProviderUri, String translationProviderState, ITranslationProviderCredentialStore
                    credentialStore, Boolean performUpdate, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.GetTranslationProviderLanguageDirection(TranslationProviderItem translationProviderItem, LanguagePair languageDirection,
                    Boolean performUpdate, Boolean refreshCache)
                       --- End of inner exception stack trace ---
                       at Sdl.ProjectAutomation.FileBased.Internal.AutomationServerEvents.HandleTranslationProviderException(TranslationProviderItem translationProviderItem, Exception
                    exception)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.GetTranslationProviderLanguageDirection(TranslationProviderItem translationProviderItem, LanguagePair languageDirection,
                    Boolean performUpdate, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.CreateProjectCascadeEntries(IList`1 projectCascadeEntryDataList, LanguagePair languagePair, Boolean readOnly, Boolean
                    refreshCache)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.CreateCascade(ProjectCascadeSettings projectCascadeSettings, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.LanguageDirectionHelper.CreateCascade(ILanguageDirection languageDirection, ProjectCascadeEntryDataFilterFunction filter, IComparer`1 sort,
                    Boolean readOnly, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.<>c__DisplayClass5_0.<GetRecognizers>b__0()
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.GetOrCreateObject(String key, Func`1 createObject)
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.GetRecognizers(ILanguageDirection languageDirection)
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.GetLanguageTools(ILanguageDirection languageDirection)
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisDataCollectorX.CreateAnalysisDataStorage(ILanguageDirection languageDirection, AnalysisTaskSettings analysisSettings,
                    TranslationMemorySettings translationMemorySettings, ILanguageObjectsCache objectsCache)
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisDataCollectorX.Initialize(IList`1 files)
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.CreateAnalysisDataCollectors()
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.InitializeTask(IExecutingAutomaticTask task)
                       at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.InitializeTaskImplementations()
                       --- End of inner exception stack trace ---
                       at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.InitializeTaskImplementations()
                       at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.Execute()
                       at Sdl.ProjectApi.Implementation.AutomaticTaskExecuter.Execute()
                       --- End of inner exception stack trace ---

  • Stack trace using NLog 4.0.0.0 (my Studio 15 folder has v4.3.2894 installed)

    ProjectFileId :
    Source        : AutomaticTaskExecuter
    Message       : Unexpected exception when initializing task 'Analyze Files': Failed to create an instance of translation provider
                    'deepltranslationprovider:///?formality=Default&sendPlain=False'..
    Level         : Error
    Exception     : Sdl.ProjectAutomation.Core.ProjectAutomationException: Unexpected exception when initializing task 'Analyze Files': Failed to create an instance of translation provider
                    'deepltranslationprovider:///?formality=Default&sendPlain=False'.. ---> Sdl.ProjectApi.ProjectApiException: Unexpected exception when initializing task 'Analyze Files':
                    Failed to create an instance of translation provider 'deepltranslationprovider:///?formality=Default&sendPlain=False'.. --->
                    Sdl.ProjectAutomation.Core.ProjectAutomationException: Failed to create an instance of translation provider
                    'deepltranslationprovider:///?formality=Default&sendPlain=False'. ---> System.TypeInitializationException: The type initializer for
                    'Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter' threw an exception. ---> System.MissingMethodException: Method not found: 'Void
                    NLog.Config.LoggingConfiguration.AddTarget(NLog.Targets.Target)'.
                       at Sdl.Community.DeepLMTProvider.Log.Setup()
                       at Sdl.Community.DeepLMTProvider.Log.GetLogger(String name)
                       at Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter..cctor()
                       --- End of inner exception stack trace ---
                       at Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter..ctor(String key, Formality formality)
                       at Sdl.Community.DeepLMTProvider.Studio.DeepLMtTranslationProviderFactory.CreateTranslationProvider(Uri translationProviderUri, String translationProviderState,
                    ITranslationProviderCredentialStore credentialStore)
                       at Sdl.LanguagePlatform.TranslationMemoryApi.TranslationProviderManager.CreateTranslationProvider(Uri translationProviderUri, String translationProviderState,
                    ITranslationProviderCredentialStore credentialStore)
                       at Sdl.ProjectApi.TranslationProviderCache.CreateTranslationProvider(Uri translationProviderUri, String translationProviderState, ITranslationProviderCredentialStore
                    credentialStore)
                       at Sdl.ProjectApi.TranslationProviderCache.GetTranslationProvider(Uri translationProviderUri, String translationProviderState, ITranslationProviderCredentialStore
                    credentialStore, Boolean performUpdate, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.GetTranslationProviderLanguageDirection(TranslationProviderItem translationProviderItem, LanguagePair languageDirection,
                    Boolean performUpdate, Boolean refreshCache)
                       --- End of inner exception stack trace ---
                       at Sdl.ProjectAutomation.FileBased.Internal.AutomationServerEvents.HandleTranslationProviderException(TranslationProviderItem translationProviderItem, Exception
                    exception)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.GetTranslationProviderLanguageDirection(TranslationProviderItem translationProviderItem, LanguagePair languageDirection,
                    Boolean performUpdate, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.CreateProjectCascadeEntries(IList`1 projectCascadeEntryDataList, LanguagePair languagePair, Boolean readOnly, Boolean
                    refreshCache)
                       at Sdl.ProjectApi.Helpers.ProjectCascadeFactory.CreateCascade(ProjectCascadeSettings projectCascadeSettings, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.LanguageDirectionHelper.CreateCascade(ILanguageDirection languageDirection, ProjectCascadeEntryDataFilterFunction filter, IComparer`1 sort,
                    Boolean readOnly, Boolean refreshCache)
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.<>c__DisplayClass5_0.<GetRecognizers>b__0()
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.GetOrCreateObject(String key, Func`1 createObject)
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.GetRecognizers(ILanguageDirection languageDirection)
                       at Sdl.ProjectApi.Helpers.LanguageObjectsCache.GetLanguageTools(ILanguageDirection languageDirection)
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisDataCollectorX.CreateAnalysisDataStorage(ILanguageDirection languageDirection, AnalysisTaskSettings analysisSettings,
                    TranslationMemorySettings translationMemorySettings, ILanguageObjectsCache objectsCache)
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisDataCollectorX.Initialize(IList`1 files)
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.CreateAnalysisDataCollectors()
                       at Sdl.ProjectApi.AutomaticTasks.Analysis.AnalysisTask.InitializeTask(IExecutingAutomaticTask task)
                       at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.InitializeTaskImplementations()
                       --- End of inner exception stack trace ---
                       at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.InitializeTaskImplementations()
                       at Sdl.ProjectApi.Implementation.TaskExecution.ContentProcessingTaskImplementation.Execute()
                       at Sdl.ProjectApi.Implementation.AutomaticTaskExecuter.Execute()
                       --- End of inner exception stack trace ---

  • I could it get it to work with Nlog.dll bundled with Studio 15. I didn't work either with Nlog 4.4.0 from Nuget, as per second stack trace. It worked using the following version though https://www.nuget.org/packages/NLog/4.3.11

    However, I am still getting a credentials error when PreTranslating. Workarounds here don't seem to work for me:

    DeepLTranslationProviderConnecter: 2022-02-15 18:42:27.9071 Error System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
    at Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter.GetSupportedLanguages(String type, String apiKey)
    at Sdl.Community.DeepLMTProvider.Studio.DeepLTranslationProviderConnecter.GetSupportedSourceLanguages(String apiKey)

    However, when pretranslating from Trados a project created programmatically it works.

  • Hi ,

    Please try the following to identify if the issue can be resolved by including the translation provider programmatically, as opposed to recovering it from the project template

    1. Add the following code in your project automation project
    2. Substitute <api_key> with your valid API Key from DeepL
    3. Use a project template that doesn't have any TM provider saved with it's settings to avoid misinterpreting the results.

    private static void AddTranslationProvider(FileBasedProject project)
    {
           var uri_scheme = "deepltranslationprovider:///";
           var formality = "Default";
           var sendPlain = "False";
           var uri = new Uri($"{uri_scheme}?formality={formality}&sendPlain={sendPlain}");
     
           var tmConfig = project.GetTranslationProviderConfiguration();
           var provider = new TranslationProviderReference(uri, string.Empty, true);
           var entry = new TranslationProviderCascadeEntry(provider, false, true, true, 0);
           tmConfig.Entries.Add(entry);
           project.UpdateTranslationProviderConfiguration(tmConfig);
     
           var credential_uri_scheme = "deepltranslationprovider:///";
           var apiKey = "<api_key>";
           project.Credentials.AddCredential(new Uri(credential_uri_scheme), apiKey);
           project.Save();
    }

    let me know how it goes

  • Hi ,

    Can you confirm that your DeepL API key is valid?

    reference from DeepL API document.

    403 Authorization failed. Please supply a valid auth_key parameter.

    https://www.deepl.com/docs-api/accessing-the-api/error-handling/