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
  • Hi Tom,

              There is a configuration issue in CU 4 that will be handled in CU 5 that will be released in the following months. In the meantime you can bypass this error using reflection like this  :

    1.) Add the following nuget package to your project or download it and extract the dll's : https://www.nuget.org/packages/SimpleInjector/

    2.) Using reflection we need to inject the container to GlobalServices so it can properly register all the services. Be aware that I put in the default location for that dll however if you have the API copied into another location you will have to change the path. Below is a code sample how to do that in C# : 

           var container = new SimpleInjector.Container();

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

           Type myType = a.GetType("Sdl.Desktop.Platform.Services.GlobalServices");

           MethodInfo myMethod = myType.GetMethod("RegisterStandardServices");

           myMethod.Invoke(null, new object[] { container });

    Best regards,
    Robert

  • Hi Robert,

    I'm getting the same error trying to follow the command line example in the API documentation (I'm new to C#). Could you please elaborate on your code sample? How do I use it when creating a new FileBasedProject?

    Thanks!

    Henk

  • Hi Henk,

            Is there an way for you to upgrade to CU 5? That would make my code sample obsolete and you don't have to worry about it. 

    Best regards,

    Robert

  • Hi - just to add to what Robert said - we are in the late stages of beta testing CU5 and hope to release it very soon. Thanks, Daniel

    Daniel Brockmann
    Team Trados @ RWS

  • Hi Robert,

    According to the reply from Daniel Brockman, CU5 is going to be released soon, so I suppose I have to wait for it to arrive in my account. Hopefully very soon means this week, or perhaps next week? Or perhaps you can give me more info about your workaround anyway :-) ?

    Regards,

    Henk

  • 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

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