Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
34bba7f
Add Assumed internal assertion API with conditional interpolated stri…
DustinCampbell Apr 17, 2026
12b944c
Use Assumed in Framework rather than FrameworkErrorUtilities
DustinCampbell Apr 17, 2026
e796432
Add string comparison overloads, collection NotNullOrEmpty, and Inter…
DustinCampbell May 7, 2026
86ec394
Replace ErrorUtilities.VerifyThrowArgumentNull with ArgumentNullExcep…
DustinCampbell May 8, 2026
94bd7a6
Replace ErrorUtilities.VerifyThrowArgumentLength with ArgumentExcepti…
DustinCampbell May 8, 2026
982ca3b
Replace ErrorUtilities.VerifyThrowArgumentOutOfRange with ArgumentOut…
DustinCampbell May 8, 2026
d7b25cb
Refactor VerifyCollectionCopyToArguments signature and docs
DustinCampbell May 8, 2026
6c96504
Replace ErrorUtilities.VerifyThrowArgumentLength<T> with ArgumentExce…
DustinCampbell May 8, 2026
899b684
Replace ErrorUtilities.VerifyThrowObjectDisposed with ObjectDisposedE…
DustinCampbell May 8, 2026
4e39887
Replace ErrorUtilities.ThrowInternalErrorUnreachable with Assumed.Unr…
DustinCampbell May 8, 2026
cf38a49
Replace ErrorUtilities.VerifyThrowInternalNull with Assumed.NotNull
DustinCampbell May 8, 2026
5fa8305
Replace ErrorUtilities.VerifyThrowInternalLength with Assumed.NotNull…
DustinCampbell May 8, 2026
b109540
Replace ErrorUtilities.VerifyThrow with Assumed methods
DustinCampbell May 14, 2026
2dcf8f4
Replace ErrorUtilities.VerifyThrowInternalErrorUnreachable with Assum…
DustinCampbell May 14, 2026
6305027
Replace ErrorUtilities.ThrowInternalError with InternalError.Throw
DustinCampbell May 14, 2026
c9975ca
Replace EscapeHatches.ThrowInternalError with InternalError.Throw
DustinCampbell May 15, 2026
43d0d9f
Replace InternalError.Throw calls with Assumed methods and Throw<T>
DustinCampbell May 15, 2026
9d4cf23
Merge branch 'main' into assumptions
DustinCampbell May 18, 2026
d33b5b3
Merge branch 'main' into assumptions
DustinCampbell May 19, 2026
1abfb06
Merge branch 'main' into assumptions
DustinCampbell May 20, 2026
916ef8e
Replace InternalErrorException throws with Assumed/InternalError helpers
DustinCampbell May 20, 2026
8860a78
Merge branch 'main' into assumptions
DustinCampbell May 21, 2026
3f1a797
Merge branch 'main' into assumptions
DustinCampbell May 21, 2026
dafae36
Merge branch 'main' into assumptions
DustinCampbell May 22, 2026
8ce485f
Merge branch 'main' into assumptions
DustinCampbell May 26, 2026
4f4a8ec
Merge branch 'main' into assumptions
DustinCampbell May 27, 2026
34cebf4
Merge branch 'main' into assumptions
DustinCampbell May 28, 2026
9ca6c76
Merge branch 'main' into assumptions
DustinCampbell May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
45 changes: 19 additions & 26 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public BuildManager()
/// </summary>
public BuildManager(string hostName)
{
ErrorUtilities.VerifyThrowArgumentNull(hostName);
ArgumentNullException.ThrowIfNull(hostName);

_hostName = hostName;
_buildManagerState = BuildManagerState.Idle;
Expand Down Expand Up @@ -932,7 +932,7 @@ public ProjectInstance GetProjectInstanceForBuild(Project project)
new ConfigurationMetadata(project),
(config, loadProject) => CreateConfiguration(project, config),
loadProject: true);
ErrorUtilities.VerifyThrow(configuration.Project != null, "Configuration should have been loaded.");
Assumed.NotNull(configuration.Project, "Configuration should have been loaded.");
return configuration.Project!;
}
}
Expand Down Expand Up @@ -965,7 +965,7 @@ private BuildSubmissionBase<TRequestData, TResultData> PendBuildRequest<TRequest
{
lock (_syncLock)
{
ErrorUtilities.VerifyThrowArgumentNull(requestData);
ArgumentNullException.ThrowIfNull(requestData);
ErrorIfState(BuildManagerState.WaitingForBuildToComplete, "WaitingForEndOfBuild");
ErrorIfState(BuildManagerState.Idle, "NoBuildInProgress");
VerifyStateInternal(BuildManagerState.Building);
Expand Down Expand Up @@ -1064,8 +1064,8 @@ public void EndBuild()

Task projectCacheDispose = _projectCacheService!.DisposeAsync().AsTask();

ErrorUtilities.VerifyThrow(_buildSubmissions.Count == 0, "All submissions not yet complete.");
ErrorUtilities.VerifyThrow(_activeNodes.Count == 0, "All nodes not yet shut down.");
Assumed.Zero(_buildSubmissions.Count, "All submissions not yet complete.");
Assumed.Zero(_activeNodes.Count, "All nodes not yet shut down.");

if (_buildParameters!.UsesOutputCache())
{
Expand Down Expand Up @@ -1492,8 +1492,8 @@ TComponent IBuildComponentHost.GetComponent<TComponent>(BuildComponentType type)
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Complex class might need refactoring to separate scheduling elements from submission elements.")]
private void ExecuteSubmission(BuildSubmission submission, bool allowMainThreadBuild)
{
ErrorUtilities.VerifyThrowArgumentNull(submission);
ErrorUtilities.VerifyThrow(!submission.IsCompleted, "Submission already complete.");
ArgumentNullException.ThrowIfNull(submission);
Assumed.False(submission.IsCompleted, "Submission already complete.");

BuildRequestConfiguration? resolvedConfiguration = null;
bool shuttingDown = false;
Expand Down Expand Up @@ -1532,9 +1532,7 @@ private void ExecuteSubmission(BuildSubmission submission, bool allowMainThreadB
// If we have an unnamed project, assign it a temporary name.
if (string.IsNullOrEmpty(submission.BuildRequestData.ProjectFullPath))
{
ErrorUtilities.VerifyThrow(
submission.BuildRequestData.ProjectInstance != null,
"Unexpected null path for a submission with no ProjectInstance.");
Assumed.NotNull(submission.BuildRequestData.ProjectInstance, "Unexpected null path for a submission with no ProjectInstance.");

// If we have already named this instance when it was submitted previously during this build, use the same
// name so that we get the same configuration (and thus don't cause it to rebuild.)
Expand Down Expand Up @@ -1606,7 +1604,7 @@ private void ExecuteSubmission(BuildSubmission submission, bool allowMainThreadB
Debug.Assert(!Monitor.IsEntered(_syncLock));
if (shuttingDown)
{
ErrorUtilities.VerifyThrow(resolvedConfiguration is not null, "Cannot call project cache without having BuildRequestConfiguration");
Assumed.NotNull(resolvedConfiguration, "Cannot call project cache without having BuildRequestConfiguration");
// We were already canceled!
CompleteSubmissionWithException(submission, resolvedConfiguration!, new BuildAbortedException());
}
Expand Down Expand Up @@ -1727,7 +1725,7 @@ private void LoadSolutionIntoConfiguration(BuildRequestConfiguration config, Bui
return;
}

ErrorUtilities.VerifyThrow(FileUtilities.IsSolutionFilename(config.ProjectFullPath), $"{config.ProjectFullPath} is not a solution");
Assumed.True(FileUtilities.IsSolutionFilename(config.ProjectFullPath), $"{config.ProjectFullPath} is not a solution");

var buildEventContext = request.BuildEventContext;
if (buildEventContext == BuildEventContext.Invalid)
Expand Down Expand Up @@ -1899,7 +1897,7 @@ private void ProcessPacket(int node, INodePacket packet)
break;

default:
ErrorUtilities.ThrowInternalError($"Unexpected packet received by BuildManager: {packet.Type}");
Assumed.Unreachable($"Unexpected packet received by BuildManager: {packet.Type}");
break;
}
}
Expand Down Expand Up @@ -2223,9 +2221,7 @@ private void ExecuteGraphBuildScheduler(GraphBuildSubmission submission)
DumpGraph(projectGraph);
}

ErrorUtilities.VerifyThrow(
submission.BuildResult?.Exception == null,
"Exceptions only get set when the graph submission gets completed with an exception in OnThreadException. That should not happen during graph builds.");
Assumed.Null(submission.BuildResult?.Exception, "Exceptions only get set when the graph submission gets completed with an exception in OnThreadException. That should not happen during graph builds.");

// The overall submission is complete, so report it as complete
ReportResultsToSubmission<GraphBuildRequestData, GraphBuildResult>(
Expand Down Expand Up @@ -2391,10 +2387,7 @@ private void RequireState(BuildManagerState requiredState, string exceptionResou
/// </summary>
private void VerifyStateInternal(BuildManagerState requiredState)
{
if (_buildManagerState != requiredState)
{
ErrorUtilities.ThrowInternalError($"Expected state {requiredState}, actual state {_buildManagerState}");
}
Assumed.Equal(_buildManagerState, requiredState, $"Expected state {requiredState}, actual state {_buildManagerState}");
}

/// <summary>
Expand Down Expand Up @@ -2742,7 +2735,7 @@ private void HandleNodeShutdown(int node, NodeShutdown shutdownPacket)

_shuttingDown = true;
_executionCancellationTokenSource?.Cancel();
ErrorUtilities.VerifyThrow(_activeNodes.Contains(node), $"Unexpected shutdown from node {node} which shouldn't exist.");
Assumed.True(_activeNodes.Contains(node), $"Unexpected shutdown from node {node} which shouldn't exist.");
_activeNodes.Remove(node);

if (shutdownPacket.Reason != NodeShutdownReason.Requested)
Expand Down Expand Up @@ -2945,7 +2938,7 @@ private void PerformSchedulingActions(IEnumerable<ScheduleResponse> responses)
break;

default:
ErrorUtilities.ThrowInternalError($"Scheduling action {response.Action} not handled.");
Assumed.Unreachable($"Scheduling action {response.Action} not handled.");
break;
}
}
Expand Down Expand Up @@ -3386,7 +3379,7 @@ private static I ExpectPacketType<I>(INodePacket packet, NodePacketType expected
{
I? castPacket = packet as I;

ErrorUtilities.VerifyThrow(castPacket != null, $"Incorrect packet type: {packet.Type} should have been {expectedType}");
Assumed.NotNull(castPacket, $"Incorrect packet type: {packet.Type} should have been {expectedType}");

return castPacket;
}
Expand Down Expand Up @@ -3474,9 +3467,9 @@ private bool ReuseOldCaches(string[] inputCacheFiles)
{
Debug.Assert(Monitor.IsEntered(_syncLock));

ErrorUtilities.VerifyThrowInternalNull(inputCacheFiles);
ErrorUtilities.VerifyThrow(_configCache == null, "caches must not be set at this point");
ErrorUtilities.VerifyThrow(_resultsCache == null, "caches must not be set at this point");
Assumed.NotNull(inputCacheFiles);
Assumed.Null(_configCache, "caches must not be set at this point");
Assumed.Null(_resultsCache, "caches must not be set at this point");

try
{
Expand Down
8 changes: 4 additions & 4 deletions src/Build/BackEnd/BuildManager/BuildParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -256,7 +256,7 @@ public BuildParameters()
/// <param name="projectCollection">The ProjectCollection from which the BuildParameters should populate itself.</param>
public BuildParameters(ProjectCollection projectCollection)
{
ErrorUtilities.VerifyThrowArgumentNull(projectCollection);
ArgumentNullException.ThrowIfNull(projectCollection);

Initialize(new PropertyDictionary<ProjectPropertyInstance>(projectCollection.EnvironmentProperties), projectCollection.ProjectRootElementCache, new ToolsetProvider(projectCollection.Toolsets));

Expand All @@ -283,7 +283,7 @@ private BuildParameters(ITranslator translator)
/// </summary>
internal BuildParameters(BuildParameters other, bool resetEnvironment = false)
{
ErrorUtilities.VerifyThrowInternalNull(other);
Assumed.NotNull(other);

_buildId = other._buildId;
_culture = other._culture;
Expand Down Expand Up @@ -762,7 +762,7 @@ internal PropertyDictionary<ProjectPropertyInstance> EnvironmentPropertiesIntern

set
{
ErrorUtilities.VerifyThrowInternalNull(value, "EnvironmentPropertiesInternal");
Assumed.NotNull(value, valueExpression: "EnvironmentPropertiesInternal");
_environmentProperties = value;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Build/BackEnd/BuildManager/BuildRequestData.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.Build.Collections;
using Microsoft.Build.Experimental.BuildCheck;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;

namespace Microsoft.Build.Execution
{
Expand Down Expand Up @@ -58,11 +58,11 @@ public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, IEnumerable<string>? propertiesToTransfer)
: this(targetsToBuild, hostServices, flags, projectInstance.FullPath)
{
ErrorUtilities.VerifyThrowArgumentNull(projectInstance);
ArgumentNullException.ThrowIfNull(projectInstance);

foreach (string targetName in targetsToBuild)
{
ErrorUtilities.VerifyThrowArgumentNull(targetName, "target");
ArgumentNullException.ThrowIfNull(targetName, "target");
}

ProjectInstance = projectInstance;
Expand All @@ -87,7 +87,7 @@ public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, IEnumerable<string>? propertiesToTransfer, RequestedProjectState requestedProjectState)
: this(projectInstance, targetsToBuild, hostServices, flags, propertiesToTransfer)
{
ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState);
ArgumentNullException.ThrowIfNull(requestedProjectState);

RequestedProjectState = requestedProjectState;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public BuildRequestData(string projectFullPath, IDictionary<string, string?> glo
RequestedProjectState requestedProjectState)
: this(projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, flags)
{
ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState);
ArgumentNullException.ThrowIfNull(requestedProjectState);

RequestedProjectState = requestedProjectState;
}
Expand All @@ -138,8 +138,8 @@ public BuildRequestData(string projectFullPath, IDictionary<string, string?> glo
public BuildRequestData(string projectFullPath, IDictionary<string, string?> globalProperties, string? toolsVersion, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags)
: this(targetsToBuild, hostServices, flags, FileUtilities.NormalizePath(projectFullPath)!)
{
ErrorUtilities.VerifyThrowArgumentLength(projectFullPath);
ErrorUtilities.VerifyThrowArgumentNull(globalProperties);
ArgumentException.ThrowIfNullOrEmpty(projectFullPath);
ArgumentNullException.ThrowIfNull(globalProperties);

GlobalPropertiesDictionary = new PropertyDictionary<ProjectPropertyInstance>(globalProperties.Count);
foreach (KeyValuePair<string, string?> propertyPair in globalProperties)
Expand Down
6 changes: 3 additions & 3 deletions src/Build/BackEnd/BuildManager/BuildRequestDataBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.Build.Shared;

namespace Microsoft.Build.Execution
{
Expand All @@ -13,10 +13,10 @@ protected BuildRequestDataBase(
BuildRequestDataFlags flags,
HostServices? hostServices)
{
ErrorUtilities.VerifyThrowArgumentNull(targetNames);
ArgumentNullException.ThrowIfNull(targetNames);
foreach (string targetName in targetNames)
{
ErrorUtilities.VerifyThrowArgumentNull(targetName, "target");
ArgumentNullException.ThrowIfNull(targetName, "target");
}

TargetNames = new List<string>(targetNames);
Expand Down
12 changes: 5 additions & 7 deletions src/Build/BackEnd/BuildManager/BuildSubmission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class BuildSubmissionBase<TRequestData, TResultData> : BuildSubm
protected internal BuildSubmissionBase(BuildManager buildManager, int submissionId, TRequestData requestData)
: base(buildManager, submissionId)
{
ErrorUtilities.VerifyThrowArgumentNull(requestData);
ArgumentNullException.ThrowIfNull(requestData);
BuildRequestData = requestData;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ private protected void ExecuteAsync(
/// </summary>
internal void CompleteResults(TResultData result)
{
ErrorUtilities.VerifyThrowArgumentNull(result);
ArgumentNullException.ThrowIfNull(result);
CheckResultValidForCompletion(result);

BuildResult ??= result;
Expand Down Expand Up @@ -196,8 +196,7 @@ public override BuildResult Execute()

legacyThreadingData.UnregisterSubmissionForLegacyThread(SubmissionId);

ErrorUtilities.VerifyThrow(BuildResult != null,
"BuildResult is not populated after Execute is done.");
Assumed.NotNull(BuildResult, "BuildResult is not populated after Execute is done.");

return BuildResult!;
}
Expand All @@ -214,8 +213,7 @@ internal override bool IsStarted

protected internal override BuildResult CreateFailedResult(Exception exception)
{
ErrorUtilities.VerifyThrow(BuildRequest != null,
"BuildRequest is not populated while reporting failed result.");
Assumed.NotNull(BuildRequest, "BuildRequest is not populated while reporting failed result.");
return new(BuildRequest!, exception);
}

Expand All @@ -227,7 +225,7 @@ protected internal override void CheckResultValidForCompletion(BuildResult resul
// this one.)
if (result.ConfigurationId != BuildRequest?.ConfigurationId)
{
ErrorUtilities.ThrowInternalError($"BuildResult configuration ({result.ConfigurationId}) doesn't match BuildRequest configuration ({BuildRequest?.ConfigurationId})");
InternalError.Throw($"BuildResult configuration ({result.ConfigurationId}) doesn't match BuildRequest configuration ({BuildRequest?.ConfigurationId})");
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Build/BackEnd/BuildManager/BuildSubmissionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Threading;
using Microsoft.Build.Shared;

namespace Microsoft.Build.Execution
{
Expand Down Expand Up @@ -36,7 +35,7 @@ public abstract class BuildSubmissionBase
/// </summary>
protected internal BuildSubmissionBase(BuildManager buildManager, int submissionId)
{
ErrorUtilities.VerifyThrowArgumentNull(buildManager);
ArgumentNullException.ThrowIfNull(buildManager);

BuildManager = buildManager;
SubmissionId = submissionId;
Expand Down
Loading