private async Task NotifyCpsProjectSystemAsync( IProjectItemDesignerTypeUpdateService updateService, DesignerAttributeData data, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { await updateService.SetProjectItemDesignerTypeAsync(data.FilePath, data.Category).ConfigureAwait(false); } catch (ObjectDisposedException) { // we might call update service after project is already removed and get object disposed exception. // we will catch the exception and ignore. // see this PR for more detail - https://github.com/dotnet/roslyn/pull/35383 } }
private void NotifyLegacyProjectSystemOnUIThread( IVSMDDesignerService designerService, IVsHierarchy hierarchy, DesignerAttributeData data) { this.AssertIsForeground(); var itemId = hierarchy.TryGetItemId(data.FilePath); if (itemId == VSConstants.VSITEMID_NIL) { return; } // PERF: Avoid sending the message if the project system already has the current value. if (ErrorHandler.Succeeded(hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ItemSubType, out var currentValue))) { var currentStringValue = string.IsNullOrEmpty(currentValue as string) ? null : (string)currentValue; if (string.Equals(currentStringValue, data.Category, StringComparison.OrdinalIgnoreCase)) { return; } } try { designerService.RegisterDesignViewAttribute( hierarchy, (int)itemId, dwClass: 0, pwszAttributeValue: data.Category); } catch { // DevDiv # 933717 // turns out RegisterDesignViewAttribute can throw in certain cases such as a file failed to be checked out by source control // or IVSHierarchy failed to set a property for this project // // just swallow it. don't crash VS. } }