studio.GetStudioVersion() throws NullReferenceException

When developing a plugin against Studio 2017 I was able to determine the current version of Studio by calling

   var studio = new Studio();
   var version = studio.GetStudioVersion();

However, when run against Studio 2019 this throws a NullReferenceException (with the standard "Object reference not set to an instance of an object." message) with this basic stack trace

   at Sdl.Community.Toolkit.Core.Services.StudioVersionService.GetStudioVersion()
   at Sdl.Community.Toolkit.Core.Studio.GetStudioVersion()

Curiously, there's also a method studio.GetInstalledStudioVersion(), which returns

Screenshot showing the output of studio.GetInstalledStudioVersion() method with a count of 1, indicating only SDL Studio 2017 is recognized as installed.

...even though I have both 2017 and 2019 installed.

Ultimately what I'm trying to achieve is the path to the user's default 'Projects' directory.

Can anyone explain

  1. Why do I get this exception now, with Trados Studio 2019?
    (The studio object comes from the Sdl.Community.Toolkit.Core.Studio2017 NuGet package, and there doesn't appear to be a 2019 version of the package.)
  2. Why does studio.GetInstalledStudioVersion() say that only 2017 is installed?
    (I realise this could be due to a shortcoming of the Sdl.Community.Toolkit.Core.Studio2017 NuGet package, but what's the point in having such a method if it can only recognise a single version?)
  3. Is there a better way of determining the user's default \Projects directory?


Generated Image Alt-Text
[edited by: Trados AI at 1:11 PM (GMT 0) on 5 Mar 2024]