From 07509901790926cb8a1a65ce6f3defa5928e243b Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 10 Jul 2017 10:02:30 -0700 Subject: [PATCH] Handle null connections. --- .../Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs | 4 +++- .../Core/Next/Remote/ServiceHubRemoteHostClient.cs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs index ce85e5526fc..d7fa8d3093a 100644 --- a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs +++ b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs @@ -39,7 +39,9 @@ private class WorkspaceHost : ForegroundThreadAffinitizedObject, IVisualStudioWo _workspace = workspace; _client = client; _currentSolutionId = workspace.CurrentSolution.Id; - _currentConnection = new ReferenceCountedDisposable.WeakReference(currentConnection); + _currentConnection = currentConnection == null + ? default + : new ReferenceCountedDisposable.WeakReference(currentConnection); } public void OnAfterWorkingFolderChange() diff --git a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs index e27f422a12a..a7a33214a3d 100644 --- a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs +++ b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.cs @@ -80,7 +80,10 @@ private static async Task RegisterWorkspaceHostAsync(Workspace workspace, Remote // projectTracker is sending events, the workspace host can then use that connection // instead of having to expensively spin up a fresh one. var currentConnection = await client.TryCreateConnectionAsync(WellKnownRemoteHostServices.RemoteHostService, CancellationToken.None).ConfigureAwait(false); - using (var refCountedConnection = new ReferenceCountedDisposable(currentConnection)) + var refCountedConnection = currentConnection == null + ? null + : new ReferenceCountedDisposable(currentConnection); + using (refCountedConnection) { var host = new WorkspaceHost(vsWorkspace, client, refCountedConnection); -- GitLab