diff --git a/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs b/src/VisualStudio/Core/Next/Remote/ServiceHubRemoteHostClient.WorkspaceHost.cs index ce85e5526fc27cf3c364fdc034f37748483a9d20..d7fa8d3093a0383699a53cea1e12828328a5216f 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 e27f422a12af7cabb185690eb0630fc4df5b4e4c..a7a33214a3d9ba6604a50491bf726adc3a5fcd99 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);