/// <include file='doc\DesignerPackage.uex' path='docs/doc[@for="DesignerPackage.ShowError2"]/*' />
        /// <devdoc>
        ///     Displays the given Exception and it's info in a message box.  This properly integrates the
        ///     message box display with the development environment.
        /// </devdoc>
        public void ShowError(Exception ex, string message)
        {
            IVsUIShell uishell = (IVsUIShell)GetService(typeof(IVsUIShell));

            if (message == null || message.Length == 0)
            {
                message = ex.ToString();
            }

            if (uishell != null)
            {
                int hr = 0;

                if (ex is ExternalException)
                {
                    hr = ((ExternalException)ex).ErrorCode;
                }

                // IUIShell will not show an error with a success code.
                //
                if (NativeMethods.Succeeded(hr))
                {
                    hr = NativeMethods.E_FAIL;
                }

                uishell.SetErrorInfo(hr, message, 0, ex.HelpLink, ex.Source);
                uishell.ReportErrorInfo(hr);
            }
            else
            {
                MessageBox.Show(message, null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #2
0
        public override int EnumPorts(out IEnumDebugPorts2 ppEnum)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_distros == null)
            {
                IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;

                try
                {
                    WSLCommandLine.EnsureInitialized();
                    _distros = WSLCommandLine.GetInstalledDistros();
                }
                catch (Exception ex)
                {
                    shell.SetErrorInfo(ex.HResult, ex.Message, 0, null, null);
                    shell.ReportErrorInfo(ex.HResult);
                    ppEnum = null;
                    return(VSConstants.E_ABORT);
                }
            }

            WSLPort[] ports = _distros.Select(name => new WSLPort(this, name, isInAddPort: false)).ToArray();
            ppEnum = new AD7PortEnum(ports);
            return(HR.S_OK);
        }
Example #3
0
        /// <summary>
        /// Uses IVsUIShell to display the error associated with the hr. Will look for an error string on the current thread that was
        /// set by SetErrorInfo() and use that. Otherwise, tries to get the best error from the hResult.
        /// </summary>
        public void ReportErrorInfo(int hr)
        {
            _threadingService.VerifyOnUIThread();

            IVsUIShell vsUIShell = _serviceProvider.GetService <IVsUIShell, SVsUIShell>();

            int result = vsUIShell.ReportErrorInfo(hr);
        }
        /// <include file='doc\DesignerPackage.uex' path='docs/doc[@for="DesignerPackage.ShowError"]/*' />
        /// <devdoc>
        ///     Displays the given error message in a message box.  This properly integrates the
        ///     message box display with the development environment.
        /// </devdoc>
        public void ShowError(string message)
        {
            IVsUIShell uishell = (IVsUIShell)GetService(typeof(IVsUIShell));

            if (uishell != null)
            {
                uishell.SetErrorInfo(NativeMethods.E_FAIL, message, 0, null, null);
                uishell.ReportErrorInfo(NativeMethods.E_FAIL);
            }
            else
            {
                MessageBox.Show(message, null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }