System.MissingMethodException when calling TranslationProviderManager.GetTranslationProviderFactories() - plugin problem

Hello!

After upgrading Trados Studio from version 17.0.3.11695 to 17.2.8.18668 we have a problem with Sdl.LanguagePlatform.TranslationMemoryApi.TranslationProviderManager.GetTranslationProviderFactories() method.

When calling it we get this error:

System.MissingMethodException: No parameterless constructor defined for this object.
  at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
  at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
  at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
  at System.Activator.CreateInstance(Type type, Boolean nonPublic)
  at System.Activator.CreateInstance(Type type)
  at Sdl.Core.PluginFramework.DefaultObjectResolver.CreateObject(Type objectType, XElement attributeElement)
  at Sdl.Desktop.Platform.Implementation.ObjectResolverComposer.CreateObject(Type objectType, XElement attributeElement)
  at Sdl.Core.PluginFramework.Implementation.Extension.CreateInstance()
  at Sdl.Core.PluginFramework.ObjectRegistry`2.CreateObjects()
  at Sdl.LanguagePlatform.TranslationMemoryApi.TranslationProviderManager.GetTranslationProviderFactories()

We've discovered that the problem is caused by this file located in PlugIns directory:
Sdl.BestMatchService.TranslationProvider.plugin.xml

Very simple console app like this is enough to induce the error:

using Sdl.LanguagePlatform.TranslationMemoryApi;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            TranslationProviderManager.GetTranslationProviderFactories();
        }
    }
}

A workaround to this problem is to delete first two <extension>...</extension> sections from Sdl.BestMatchService.TranslationProvider.plugin.xml.

Uprading to 17.2.10.19084 doesn't help.

Is there more proper solution to this problem?

Cheers,
Wojtek

Parents
  •  I have one more question - do you think that the workaround I proposed to delete first two <extension>...</extension> sections from Sdl.BestMatchService.TranslationProvider.plugin.xml or deleting whole Sdl.BestMatchService.TranslationProvider.plugin.xml file can cause any problems?

  • Hi ,  The development team have reported that there will be a fix in place for the Trados Studio 2022 SR2 CU11 and 2024 CU1.

    Until then, you can use this workaround.

    1. Add a reference to Sdl.ProjectAutomation.FileBased to your project.
    2. Add this reflection helper to your code. This helper includes a method to call a private static method in FileBasedProject assembly.
    3. Call the helper method CallEnsurePluginRegistryIsCreated once, before the factory methods.

      Full code example here:
      using System;
      using System.Reflection;
      using Sdl.LanguagePlatform.TranslationMemoryApi;
      using Sdl.ProjectAutomation.FileBased;
      
      namespace ConsoleApp1
      {
          internal class Program
          {
              static void Main(string[] args)
              {
                  Console.WriteLine("Calling TranslationProviderManager.GetTranslationProviderFactories...");
                  ReflectionHelper.CallEnsurePluginRegistryIsCreated();
                  var factories = TranslationProviderManager.GetTranslationProviderFactories();
                  Console.WriteLine("Result obtained successfully: {0} objects.", factories.Count);
      
                  Console.WriteLine("Press Enter to continue...");
                  Console.ReadLine();
              }
          }
      
          public static class ReflectionHelper
          {
              public static void CallEnsurePluginRegistryIsCreated()
              {
                  // Get the type of the class containing the private static method
                  Type fileBasedProjectType = typeof(FileBasedProject);
      
                  // Get the MethodInfo object for the private static method using BindingFlags
                  MethodInfo methodInfo = fileBasedProjectType.GetMethod(
                      "EnsurePluginRegistryIsCreated",
                      BindingFlags.NonPublic | BindingFlags.Static);
      
                  // Ensure the method has been found
                  if (methodInfo == null)
                  {
                      throw new InvalidOperationException("Could not find the method EnsurePluginRegistryIsCreated");
                  }
      
                  // Invoke the private static method
                  methodInfo.Invoke(null, null);
              }
          }
      }
Reply Children
No Data