Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 06cbb0e

Browse files
committed
Disable exports and menus that would crash Blend
Only enable some exports and menus when running inside the Visual Studio process. The extension is now effectively disbled when running inside Blend.
1 parent 67fcf8d commit 06cbb0e

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
5757
async Task InitializeMenus()
5858
{
5959
var menus = await GetServiceAsync(typeof(IMenuProvider)) as IMenuProvider;
60+
if (menus == null)
61+
{
62+
// Ignore if null because Expression Blend doesn't support custom services or menu extensibility.
63+
return;
64+
}
6065

6166
await ThreadingHelper.SwitchToMainThreadAsync();
6267

src/GitHub.VisualStudio/Menus/MenuProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using GitHub.Services;
1+
using GitHub.Exports;
2+
using GitHub.Services;
23
using System.Collections.Generic;
34
using System.Collections.ObjectModel;
45
using System.ComponentModel.Composition;
@@ -14,7 +15,7 @@ namespace GitHub.VisualStudio.Menus
1415
/// redirects every request to the actual service, and can be
1516
/// thrown away as soon as the caller is done (no state is kept)
1617
/// </summary>
17-
[Export(typeof(IMenuProvider))]
18+
[ExportForProcess(typeof(IMenuProvider), "devenv")]
1819
[PartCreationPolicy(CreationPolicy.NonShared)]
1920
public class MenuProviderDispatcher : IMenuProvider
2021
{

src/GitHub.VisualStudio/Services/GitHubServiceProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Reactive.Linq;
1212
using GitHub.Infrastructure;
1313
using GitHub.Models;
14+
using GitHub.Exports;
1415
using GitHub.Services;
1516
using GitHub.UI;
1617
using Microsoft.VisualStudio.ComponentModelHost;
@@ -28,7 +29,7 @@ namespace GitHub.VisualStudio
2829
/// redirects every request to the actual service, and can be
2930
/// thrown away as soon as the caller is done (no state is kept)
3031
/// </summary>
31-
[Export(typeof(IGitHubServiceProvider))]
32+
[ExportForProcess(typeof(IGitHubServiceProvider), "devenv")]
3233
[PartCreationPolicy(CreationPolicy.NonShared)]
3334
[NullGuard(ValidationFlags.None)]
3435
public class GitHubProviderDispatcher : IGitHubServiceProvider

src/GitHub.VisualStudio/Services/LoginManagerDispatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
using System.ComponentModel.Composition;
33
using System.Threading.Tasks;
44
using GitHub.Api;
5+
using GitHub.Exports;
56
using GitHub.Primitives;
67
using Microsoft.VisualStudio.Shell;
78
using Octokit;
89
using Task = System.Threading.Tasks.Task;
910

1011
namespace GitHub.Services
1112
{
12-
[Export(typeof(ILoginManager))]
13+
[ExportForProcess(typeof(ILoginManager), "devenv")]
1314
[PartCreationPolicy(CreationPolicy.NonShared)]
1415
public class LoginManagerDispatcher : ILoginManager
1516
{

src/GitHub.VisualStudio/Services/UsageTrackerDispatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using System;
33
using System.ComponentModel.Composition;
44
using Task = System.Threading.Tasks.Task;
5+
using GitHub.Exports;
56

67
namespace GitHub.Services
78
{
8-
[Export(typeof(IUsageTracker))]
9+
[ExportForProcess(typeof(IUsageTracker), "devenv")]
910
[PartCreationPolicy(CreationPolicy.NonShared)]
1011
public class UsageTrackerDispatcher : IUsageTracker
1112
{

0 commit comments

Comments
 (0)