diff options
author | Matt Ward <matt.ward@microsoft.com> | 2019-06-27 14:26:15 +0300 |
---|---|---|
committer | Matt Ward <matt.ward@microsoft.com> | 2019-06-27 17:15:32 +0300 |
commit | d03796219f4c8138f3edb2c97768f782e831ef48 (patch) | |
tree | bc1524c1619374ae9dc0a480daa3c527dd998ea3 /main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs | |
parent | a8cc97b50f1fece90690febd43761c157e773fe8 (diff) |
[Core] Fix null ref if RunTarget called after Project is disposed
Project.RunTarget now uses BindTask so the target will complete
before the Project is disposed. This will also prevent a null
reference exception that could occur when the MSBuildProject was
accessed in RunMSBuildTarget when RunTarget is called after the
Project is disposed. A TaskCancelationException is thrown if
RunTarget is called after the Project has been disposed.
Fixes VSTS #935875 - High exception count in MSBuild as run by the
Android Designer
Could not reproduce the above bug testing the designer. Assumption
based on the exception callstack is that RunTarget is being called
after the Project is disposed.
Diffstat (limited to 'main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs index e53cda474c..7e62055fe7 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs @@ -706,7 +706,7 @@ namespace MonoDevelop.Projects ctx.BuilderQueue = BuilderQueue.ShortOperations; ctx.LogVerbosity = MSBuildVerbosity.Quiet; - var evalResult = await project.RunTarget (monitor, dependsList, config.Selector, ctx); + var evalResult = await project.RunTargetInternal (monitor, dependsList, config.Selector, ctx); if (evalResult != null && evalResult.Items != null) { result = ProcessMSBuildItems (evalResult.Items, project); } @@ -1251,6 +1251,13 @@ namespace MonoDevelop.Projects /// </param> public Task<TargetEvaluationResult> RunTarget (ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context = null) { + return BindTask<TargetEvaluationResult> (cancelToken => { + return RunTargetInternal (monitor.WithCancellationToken (cancelToken), target, configuration, context); + }); + } + + internal Task<TargetEvaluationResult> RunTargetInternal (ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context = null) + { // Initialize the evaluation context. This initialization is shared with FastCheckNeedsBuild. // Extenders will override OnConfigureTargetEvaluationContext to add custom properties and do other // initializations required by MSBuild. @@ -1865,7 +1872,7 @@ namespace MonoDevelop.Projects protected override async Task<BuildResult> OnBuild (ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext) { var newContext = operationContext as TargetEvaluationContext ?? new TargetEvaluationContext (operationContext); - return (await RunTarget (monitor, "Build", configuration, newContext)).BuildResult; + return (await RunTargetInternal (monitor, "Build", configuration, newContext)).BuildResult; } async Task<TargetEvaluationResult> RunBuildTarget (ProgressMonitor monitor, ConfigurationSelector configuration, TargetEvaluationContext context) @@ -2250,7 +2257,7 @@ namespace MonoDevelop.Projects protected override async Task<BuildResult> OnClean (ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext buildSession) { var newContext = buildSession as TargetEvaluationContext ?? new TargetEvaluationContext (buildSession); - return (await RunTarget (monitor, "Clean", configuration, newContext)).BuildResult; + return (await RunTargetInternal (monitor, "Clean", configuration, newContext)).BuildResult; } Task<TargetEvaluationResult> RunCleanTarget (ProgressMonitor monitor, ConfigurationSelector configuration, TargetEvaluationContext context) |