TFS Duplicate Work Item Reference

I have a program that automatically links links between two work items.

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

More information: TF237099: Duplicate Work Item Reference.

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

      

How do I fix the problem?

+3


source to share


1 answer


You should check if workitem1 has a link 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();
}

      

+2


source







All Articles