When I programmatically create a new bug and set the area path to this:
VssBasicCredential credentials = new VssBasicCredential(string.Empty, personalAccessToken);
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.AreaPath",
Value = "Project"
},
WorkItem bug = await workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, project, "Bug").ConfigureAwait(false);
I get this error:
TF401346: Invalid Area/Iteration id given for work item -1, field 'System.AreaId'.
I think this is a bug, this area path exists in ADO.
The issue was not the area path but another field, for whatever reason ADO pointed to the area path as the issue. Try adding each field one by one, or area field alone to see if it fixes the issue. This is the trimmed down version of my code.
JsonPatchDocument patchDocument = new JsonPatchDocument
{
//add fields and their values to your patch document
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.Title",
Value = $"{tag} for PR #{pullRequest.PullRequestId} changes in build {buildNumber} PlannerBuildArtifact."
},
new JsonPatchOperation()
{
Operation = Operation.Add,
Path = "/fields/System.AreaPath",
Value = "Project\\Planner\\Service"
}
};
try
{
using VssConnection connection = new VssConnection(Uri, this._credentials);
using WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
return await workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, Project, "Bug").ConfigureAwait(false);
}
catch (VssException e)
{
_log.LogError("Unable to create work item", e);
throw;
}