blokblack
blokblack

Reputation: 57

TFS Duplicate work item link

I have a program which makes the links between two workitems automatically.

An unhandled exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll

Additional information: TF237099: Duplicate work item link.

WorkItemLinkType linkType = wis.WorkItemLinkTypes[CoreLinkTypeReferenceNames.Related];
tfsProblem.workitem1.Links.Add(new WorkItemLink(linkType.ForwardEnd, tfsEvent.workitem2.Id));
tfsProblem.workitem1.Save();

How to fix the problem?

Upvotes: 3

Views: 1228

Answers (1)

Peter
Peter

Reputation: 27944

You should check if there is a link in workitem1 to workitem2 before adding a new one:

LinkCollection links = tfsProblem.workitem1.Links;
if (!links.Any(x => ((Microsoft.TeamFoundation.WorkItemTracking.Client.RelatedLink) (x)).RelatedWorkItemId == tfsEvent.workitem2.Id)
{
   WorkItemLinkType linkType = wis.WorkItemLinkTypes[CoreLinkTypeReferenceNames.Related];
   tfsProblem.workitem1.Links.Add(new WorkItemLink(linkType.ForwardEnd, tfsEvent.workitem2.Id));
   tfsProblem.workitem1.Save();
}

Upvotes: 2

Related Questions