CU4 of Studio 2019 - creating the project object leads to exception: "The requested service is not available: Sdl.Desktop.Platform.Services.IUserSettingsService."

Hi guys,

I have an issue with this code:

NewProj = New FileBasedProject(NewProjInfo)

When I do this, I get "The requested service is not available: Sdl.Desktop.Platform.Services.IUserSettingsService."

I am using this line of code for 10 years to create an empty project object and it always worked. But since I installed CU4 of STudio 2019 SR1, this code does not work any longer. 

Can you shed a light please?

Thanks, 

Tom

Parents Reply
  • Hi Henk, 

              Of course, before actually doing anything in the API or calling any method you have to use reflection to inject the DI container that we use. This is done normally if you start up Studio but if you are using the API with Studio turned off then you need to do this manually. This is what the code snippet does :

    // create the instance of the object I want to inject this is available in this nuget : nuget https://www.nuget.org/packages/SimpleInjector/ you can use the latest

     var container = new SimpleInjector.Container();

    // using reflection I load Sdl.Desktop.Platform.dll from the path where I installed Studio (in my case is the default location if you copied the API dlls somewhere else you have to put that path in )

           Assembly a = Assembly.LoadFile(@"C:\Program Files (x86)\SDL\SDL Trados Studio\Studio15\Sdl.Desktop.Platform.dll");

    // reflection code 

    //give me the type
           Type myType = a.GetType("Sdl.Desktop.Platform.Services.GlobalServices");

    // give me the method
           MethodInfo myMethod = myType.GetMethod("RegisterStandardServices");

    // because the GlobalServieces class is static I can call the method and inject the object I want see below
           myMethod.Invoke(null, new object[] { container });

    Having this object injected into the static class the API won't crash anymore. From CU 5 please remove this code as the API will handle this scenario also and it might cause compatibility issues moving forward. 

    I hope this clarifies things. 

    Best regards,

    Robert

Children