From 0268ff2baadf237ac9a32550f6e737698856b1bf Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 10 Jul 2019 18:36:57 +1000 Subject: [PATCH] Fix NRE due to dataflow race It was possible for ProcessProjectChanged to be called before _broadcastBlock was assigned, leading to a NRE when it was dereferenced. --- .../ProjectSystem/VS/PotentialEditorConfigDataSource.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PotentialEditorConfigDataSource.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PotentialEditorConfigDataSource.cs index f88227e86c5..27738c9b528 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PotentialEditorConfigDataSource.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/PotentialEditorConfigDataSource.cs @@ -58,6 +58,8 @@ protected override void Initialize() { base.Initialize(); + _broadcastBlock = DataflowBlockSlim.CreateBroadcastBlock>(nameFormat: nameof(PotentialEditorConfigDataSource) + "Broadcast {1}"); + IDisposable projectRuleSourceLink = _project.Services.ProjectSubscription.ProjectRuleSource.SourceBlock.LinkToAsyncAction(ProcessProjectChanged, ruleNames: PotentialEditorConfigFiles.SchemaName); IDisposable join = JoinUpstreamDataSources(_project.Services.ProjectSubscription.ProjectRuleSource); @@ -66,7 +68,6 @@ protected override void Initialize() _disposables.AddDisposable(projectRuleSourceLink); _disposables.AddDisposable(join); - _broadcastBlock = DataflowBlockSlim.CreateBroadcastBlock>(nameFormat: nameof(PotentialEditorConfigDataSource) + "Broadcast {1}"); _publicBlock = _broadcastBlock.SafePublicize(); }