(扩展开发)ObjectExplorerService 在 SSMS v19 中为 null

(Extension development) ObjectExplorerService is null in SSMS v19

提问人:Wonk 提问时间:6/28/2023 更新时间:6/28/2023 访问量:28

问:

我正在为 SQL Server Management Studio 制作扩展,它在 SSMS 18.x 中工作正常,但是当我运行 SSMS 19 的扩展时,尝试获取对象资源管理器服务始终返回 null。

这是包的代码:

        /// <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);
            }
        }

相同的代码在 SSMS 18 上运行良好,我们使用的是 .NET Framework 4.7.2。有什么想法吗?

我在网上查看,但似乎找不到任何相关文档或指南。不过,有一些 SSMS 18 指南可以帮助我入门。

C# NullPointerException SSMS-19

评论


答: 暂无答案