/vs-extensibility-skills:handling-extension-errorsfrom vs-extensibility-skills
Handles errors and exceptions in Visual Studio extensions: try/catch, logging to Output Window, ActivityLog, TraceSource, telemetry, and user notifications. Covers VSSDK Community Toolkit and out-of-process model.
Ships in vs-extensibility-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Exceptions will occur in any extension. Handle them in a way that:
Unhandled exceptions in an in-process extension can crash the entire IDE, not just your feature. Even in the out-of-process model, unhandled exceptions terminate your extension host process, breaking all functionality until VS restarts it. Proper error handling also means choosing the right notification channel — a modal error dialog for a recoverable background issue trains users to ignore your extension, while silently swallowing errors makes bugs invisible. The patterns here ensure errors are always logged (for you) and surfaced at the right severity (for the user).
When to use this vs. alternatives:
| Severity | Action |
|---|---|
| Low — user flow unaffected | Log to Output Window or TraceSource. Optionally show a status bar message. |
| Medium — user might want to know | Log + show an info bar in the relevant tool/document window. |
| High — user flow is interrupted | Log + show a message box / user prompt so the user can acknowledge or retry. |
Always log the exception regardless of severity.
Before anything else, ensure your .pdb files ship with the VSIX. In project properties, set:
Include Debug Symbols in VSIX Container =
True
This gives you accurate stack traces in bug reports.
The simplest approach. The Log() / LogAsync() extension methods on Exception write the full stack trace to a dedicated Output Window pane.
NuGet package: Community.VisualStudio.Toolkit
Key namespace: Community.VisualStudio.Toolkit
Synchronous context:
try
{
// Do work
}
catch (Exception ex)
{
ex.Log();
}
Asynchronous context:
try
{
// Do work
}
catch (Exception ex)
{
await ex.LogAsync();
}
Each extension part can inject a TraceSource instance provided by the extensibility framework. Use it for structured diagnostics:
NuGet package: Microsoft.VisualStudio.Extensibility
Key namespace: Microsoft.VisualStudio.Extensibility
using System.Diagnostics;
public class MyCommand : Command
{
private readonly TraceSource _logger;
public MyCommand(VisualStudioExtensibility extensibility, TraceSource traceSource)
: base(extensibility)
{
_logger = traceSource;
}
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken ct)
{
try
{
// Do work
}
catch (Exception ex)
{
_logger.TraceEvent(TraceEventType.Error, 0, ex.ToString());
}
}
}
Logs are written to %TEMP%\VSLogs in .svclog XML format and can be viewed with Microsoft Service Trace Viewer.
For VSIX Community Toolkit extensions, you can create your own Output Window pane for logging:
OutputWindowPane pane = await VS.Windows.CreateOutputWindowPaneAsync("My Extension");
await pane.WriteLineAsync($"Error: {ex.Message}");
await pane.WriteLineAsync(ex.StackTrace);
NuGet package: Microsoft.VisualStudio.SDK
Key namespaces: Microsoft.VisualStudio.Shell, Microsoft.VisualStudio.Shell.Interop
IVsActivityLog log = await GetServiceAsync(typeof(SVsActivityLog)) as IVsActivityLog;
log?.LogEntry(
(uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
this.ToString(),
$"An error occurred: {ex.Message}");
The activity log writes to %APPDATA%\Microsoft\VisualStudio\<version>\ActivityLog.xml.
For Vsix Community Toolkit extensions, use:
await VS.StatusBar.ShowMessageAsync("An error occurred. See the Output Window for details.");
VSSDK:
IVsStatusbar statusBar = (IVsStatusbar)ServiceProvider.GetService(typeof(SVsStatusbar));
statusBar?.SetText("An error occurred. See the Output Window for details.");
Community Toolkit:
var model = new InfoBarModel(
new[] { new InfoBarTextSpan("Something went wrong. "),
new InfoBarHyperlink("View details") });
InfoBar infoBar = await VS.InfoBar.CreateAsync(ToolWindowGuids80.SolutionExplorer, model);
await infoBar.TryShowInfoBarUIAsync();
Info bars via raw VSSDK require
IVsInfoBarUIFactoryandIVsInfoBarHost— see the vs-message-box skill for the full VSSDK info bar pattern.
Community Toolkit:
await VS.MessageBox.ShowAsync(
"Error",
$"An unexpected error occurred: {ex.Message}",
OLEMSGICON.OLEMSGICON_CRITICAL,
OLEMSGBUTTON.OLEMSGBUTTON_OK);
VSSDK (VsShellUtilities.ShowMessageBox):
VsShellUtilities.ShowMessageBox(
this.package, // IServiceProvider (your Package instance)
$"An unexpected error occurred: {ex.Message}", // message
"Error", // title
OLEMSGICON.OLEMSGICON_CRITICAL, // icon
OLEMSGBUTTON.OLEMSGBUTTON_OK, // buttons
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); // default button
VsShellUtilities.ShowMessageBoxis the lowest-level VSSDK API and works without the Community Toolkit. The first parameter is anyIServiceProvider— typically yourAsyncPackageinstance. It returns anintmatching theVSConstants.MessageBoxResultvalues if you need to branch on the user's choice.
VisualStudio.Extensibility:
await this.Extensibility.Shell().ShowPromptAsync(
$"An unexpected error occurred: {ex.Message}",
PromptOptions.ErrorConfirm,
ct);
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken ct)
{
try
{
// Main logic
await DoWorkAsync(ct);
}
catch (OperationCanceledException)
{
// User or system cancelled — no action needed
}
catch (Exception ex)
{
_logger.TraceEvent(TraceEventType.Error, 0, ex.ToString());
await this.Extensibility.Shell().ShowPromptAsync(
$"An error occurred: {ex.Message}",
PromptOptions.ErrorConfirm,
ct);
}
}
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
try
{
// Main logic
await DoWorkAsync();
}
catch (OperationCanceledException)
{
// Cancelled — nothing to do
}
catch (Exception ex)
{
await ex.LogAsync();
await VS.MessageBox.ShowAsync(
"Error",
$"An error occurred: {ex.Message}",
OLEMSGICON.OLEMSGICON_CRITICAL,
OLEMSGBUTTON.OLEMSGBUTTON_OK);
}
}
private void Execute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
try
{
// Main logic
DoWork();
}
catch (OperationCanceledException)
{
// Cancelled — nothing to do
}
catch (Exception ex)
{
IVsActivityLog log = Package.GetGlobalService(typeof(SVsActivityLog)) as IVsActivityLog;
log?.LogEntry(
(uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
nameof(MyCommand),
ex.ToString());
VsShellUtilities.ShowMessageBox(
this.package,
$"An error occurred: {ex.Message}",
"Error",
OLEMSGICON.OLEMSGICON_CRITICAL,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
For production extensions, integrate an APM system to catch errors you can't reproduce locally:
TelemetryClient.TrackException(ex)Always mention telemetry collection in your extension's privacy statement.
Visual Studio's editor infrastructure uses IGuardedOperations to catch exceptions from MEF extension points (classifiers, taggers, etc.) so a broken extension doesn't take down the editor. If you build editor extensions, your code already benefits from this.
You can also use it explicitly:
[Import]
IGuardedOperations GuardedOperations { get; set; }
// Wraps the call and swallows + logs exceptions
GuardedOperations.CallExtensionPoint(this, () => {
// Potentially failing work
});
OperationCanceledException separately — it's normal control flow, not an error.TraceSource in the new extensibility model; use ex.Log() in the Community Toolkit.catch block should call ex.Log() (Toolkit), _logger.TraceEvent(...) (Extensibility), or write to the Activity Log (VSSDK) before any user notification.ex.Log() Toolkit helper writes to a pane named after your extension. Open the Output Window and check the Show output from dropdown — your pane may exist but not be selected.TraceSource via the constructor, not creating a new instance manually. The framework-provided TraceSource is wired to the VS logging infrastructure; a manually created one writes nowhere./Log. For development use %APPDATA%\Microsoft\VisualStudio\<version>\ActivityLog.xml. Consider the Output Window or TraceSource for day-to-day logging instead.async void method threw an unhandled exception. Search for async void and convert to async Task. See vs-async-threading.ex.ToString() or ex.StackTrace to the message box. Log the full exception, but show only ex.Message (or a friendlier summary) to the user.Do NOT swallow exceptions silently with empty
catchblocks — at minimum, log to the Output Window, TraceSource, or Activity Log.
Do NOT show raw exception messages or stack traces in user-facing message boxes — they may contain file paths or internal type names. Log the full exception; show a user-friendly summary.
Do NOT use
async void— unhandled exceptions crash the VS process. ReturnTaskand useJoinableTaskFactory.RunAsyncfor fire-and-forget.
Do NOT show modal error dialogs for recoverable background errors or during solution load — use an info bar or status bar message instead.
Do NOT create a new
TraceSourcemanually in VisualStudio.Extensibility extensions — inject the framework-provided one through the constructor.
What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (madskristensen/vs-agent-plugins) — no native marketplace selected
npx claudepluginhub p/madskristensen-vs-extensibility-skills41 skills in this plugin
/adding-codelens-indicatorsAdd custom CodeLens indicators that display inline information above code elements in the Visual Studio editor. Use when the user asks how to add a CodeLens indicator, show inline data above methods or classes, create a custom CodeLens provider, implement IAsyncCodeLensDataPointProvider, display git history or test status in CodeLens, or add a details popup to CodeLens entries. Covers VSSDK / VSIX Community Toolkit (in-process + out-of-process CodeLens service). VisualStudio.Extensibility (out-of-process) does not have a dedicated CodeLens API./adding-commandsAdd commands (menu items, toolbar buttons) to Visual Studio extensions. Use when the user asks how to create a command, add a menu item, add a toolbar button, register a command handler, wire up a .vsct file, use KnownMonikers icons on buttons, or place commands in menus/toolbars in a Visual Studio IDE extension. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-context-menusAdd native-looking context menus to custom WPF UI in Visual Studio extensions (tool windows, custom tree views, list views). Use when the user wants to show a right-click context menu from their own UI that looks native to VS. Covers defining VSCT context menus (type="Context"), grouping commands with separators, and programmatically showing them via IVsUIShell.ShowContextMenu. Do NOT use regular WPF ContextMenu — it won't match VS theming or support command routing. Covers VSSDK and VSIX Community Toolkit (in-process). VisualStudio.Extensibility (out-of-process) does not support VSCT-based context menus on custom UI.Other plugins' skills for the same job