protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true); cancellationToken.ThrowIfCancellationRequested(); Assumes.Present(_componentModel); FatalError.Handler = FailFast.OnFatalException; FatalError.NonFatalHandler = WatsonReporter.Report; // We also must set the FailFast handler for the compiler layer as well var compilerAssembly = typeof(Compilation).Assembly; var compilerFatalError = compilerAssembly.GetType("Microsoft.CodeAnalysis.FatalError", throwOnError: true); var property = compilerFatalError.GetProperty(nameof(FatalError.Handler), BindingFlags.Static | BindingFlags.Public); var compilerFailFast = compilerAssembly.GetType(typeof(FailFast).FullName, throwOnError: true); var method = compilerFailFast.GetMethod(nameof(FailFast.OnFatalException), BindingFlags.Static | BindingFlags.NonPublic); property.SetValue(null, Delegate.CreateDelegate(property.PropertyType, method)); _workspace = _componentModel.GetService <VisualStudioWorkspace>(); _workspace.Services.GetService <IExperimentationService>(); // Ensure the options persisters are loaded since we have to fetch options from the shell _componentModel.GetExtensions <IOptionPersister>(); RoslynTelemetrySetup.Initialize(this); // set workspace output pane _outputPane = new WorkspaceFailureOutputPane(_componentModel.GetService <IThreadingContext>(), this, _workspace); InitializeColors(); // load some services that have to be loaded in UI thread LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget(); _solutionEventMonitor = new SolutionEventMonitor(_workspace); TrackBulkFileOperations(); RegisterCodeCleanupProvider(); }
protected override void Initialize() { base.Initialize(); FatalError.Handler = FailFast.OnFatalException; FatalError.NonFatalHandler = WatsonReporter.Report; // We also must set the FailFast handler for the compiler layer as well var compilerAssembly = typeof(Compilation).Assembly; var compilerFatalError = compilerAssembly.GetType("Microsoft.CodeAnalysis.FatalError", throwOnError: true); var property = compilerFatalError.GetProperty(nameof(FatalError.Handler), BindingFlags.Static | BindingFlags.Public); var compilerFailFast = compilerAssembly.GetType(typeof(FailFast).FullName, throwOnError: true); var method = compilerFailFast.GetMethod(nameof(FailFast.OnFatalException), BindingFlags.Static | BindingFlags.NonPublic); property.SetValue(null, Delegate.CreateDelegate(property.PropertyType, method)); var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel)); _workspace = componentModel.GetService <VisualStudioWorkspace>(); _workspace.Services.GetService <IExperimentationService>(); RegisterFindResultsLibraryManager(); // Ensure the options persisters are loaded since we have to fetch options from the shell componentModel.GetExtensions <IOptionPersister>(); RoslynTelemetrySetup.Initialize(this); // set workspace output pane _outputPane = new WorkspaceFailureOutputPane(this, _workspace); InitializeColors(); // load some services that have to be loaded in UI thread LoadComponentsInUIContextOnceSolutionFullyLoaded(); _solutionEventMonitor = new SolutionEventMonitor(_workspace); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true); cancellationToken.ThrowIfCancellationRequested(); Assumes.Present(_componentModel); // Fetch the session synchronously on the UI thread; if this doesn't happen before we try using this on // the background thread then we will experience hangs like we see in this bug: // https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems?_a=edit&id=190808 or // https://devdiv.visualstudio.com/DevDiv/_workitems?id=296981&_a=edit var telemetrySession = TelemetryService.DefaultSession; WatsonReporter.InitializeFatalErrorHandlers(telemetrySession); // Ensure the options persisters are loaded since we have to fetch options from the shell _componentModel.GetExtensions <IOptionPersister>(); _workspace = _componentModel.GetService <VisualStudioWorkspace>(); _workspace.Services.GetService <IExperimentationService>(); RoslynTelemetrySetup.Initialize(this, telemetrySession); InitializeColors(); // load some services that have to be loaded in UI thread LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget(); _solutionEventMonitor = new SolutionEventMonitor(_workspace); TrackBulkFileOperations(); }