(Extension development) ObjectExplorerService is null in SSMS v19

47 views Asked by At

I am making an extension for SQL Server Management Studio, and it is working fine for SSMS 18.x, but when I run the extension for SSMS 19 attempting to get the Object Explorer Service always returns null.

This is the code for the package:

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
protected override void Initialize()
        {
            try
            {
                base.Initialize();

                DefaultFolder = GetDefaultFolder();
                Logger.LogFilePath = Path.Combine(DefaultFolder, "log.txt");

                SetScriptsFolderCommand.Initialize(this);
                SetDefaultFolderCommand.Initialize(this);

                ObjectExplorerService explorerService = ServiceProvider.GlobalProvider.GetService(typeof(IObjectExplorerService)) as ObjectExplorerService;

                MenuContext = (ContextService)explorerService.Container.Components[0]; 
                // System.NullReferenceException: 'Object reference not set to an instance of an object.'
                // (explorerService was null).


                ObjectBrowserMenuManager = new Managers.MenuManager(explorerService);
                ObjectBrowserMenuManager.Package = this;

                LoadScripts();

                MenuContext.ObjectExplorerContext.CurrentContextChanged += new NodesChangedEventHandler(ObjectBrowserMenuManager.ObjectExplorerContext_CurrentContextChanged);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }

The same code runs fine on SSMS 18, and we're using .NET Framework 4.7.2. Any ideas?

I've looked online but can't seem to find any relevant documentation or guides. There are some guides for SSMS 18 that helped me get started, though.

0

There are 0 answers