Iteration Path not valid error when adding work item after creating iteration path
-
Tuesday, September 01, 2009 7:07 AMHi all - I'm getting the following error:TF26202: Iteration Path is not a valid area or iteration path. In the Team menu, click Team Project Settings, and then click Areas and Iterations to review the valid area and iteration paths.I have a web form that accepts some details, including a client name. I then check that an iteration exists for that client and if not I create one. I then go about and create some work items depending on a few options the user selects. I get the error above when I create a work item straight after creating the iteration path. If I reload the page, the work items are created fine. It seems that the workitemstore isn't aware that I just created the new iteration. Is there someway to force the workitemstore to refresh before I create the work items?Cheers and thanks :)
All Replies
-
Tuesday, September 01, 2009 7:27 AMIf I sleep for 10 seconds, I dont have the issue :(
-
Tuesday, September 01, 2009 7:54 AMHi Kolchak
Do you use TFS object model to create iteration pathes and work item dynamatically? After the iteration path is added, you can call RefreshCache and SyncToCache methods to refresh the work item cache. Then you should be able to create work items with the new iteration.
Bill Wang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
Tuesday, September 01, 2009 10:21 PM
Still no joy :( Here is some code to help explain what I'm doing...// Create the iteration if it doesn't exist string iterationPath = tfsRootNode + Client.Text.Replace("\\", ""); NodeInfo nodes = createNode(iterationPath, tfsProject, StructureType.Iteration); // Now create workitem store WorkItemStore store = new WorkItemStore(tfsServerName); store.RefreshCache(); store.SyncToCache(); workItemCreated = createWorkItem(store, Title.Text, Description.Text, "Project Management", req.EstimateRequestID.ToString(), iterationPath);and the 2 called methods. First is createNode borrowed from here http://blogs.microsoft.co.il/blogs/shair/archive/2009/01/30/tfs-api-part-10-add-area-iteration-programmatically.aspxprivate NodeInfo createNode(string ElementPath, string projectName, StructureType nodeType) { var srv = new TeamFoundationServer(tfsServerName); ICommonStructureService css = (ICommonStructureService)srv.GetService(typeof(ICommonStructureService)); NodeInfo retVal; string rootNodePath = "\\" + projectName + "\\" + nodeType.ToString(); //Check if this path already exsist string newPath = rootNodePath + ElementPath; try { retVal = css.GetNodeFromPath(newPath); if (retVal != null) { return null; //already exists } } catch (Exception ex) { if (ex.Message.Contains("The following node does not exist")) { //just means that this path is not exist and we can continue. } else { throw ex; } } int BackSlashIndex = ElementPath.LastIndexOf("\\"); string Newpathname = ElementPath.Substring(BackSlashIndex + 1); string NewPath = (BackSlashIndex == 0 ? string.Empty : ElementPath.Substring(0, BackSlashIndex)); string PathRoot = rootNodePath + NewPath; NodeInfo previousPath = null; try { previousPath = css.GetNodeFromPath(PathRoot); } catch (Exception ex) { if (ex.Message.Contains("Invalid path.")) { //just means that this path is not exist and we can continue. previousPath = null; } else { throw ex; } } if (previousPath == null) { //call this method to create the parent paths. previousPath = createNode(NewPath, projectName, nodeType); } string newPathUri = css.CreateNode(Newpathname, previousPath.Uri); // HACK: Ouch! No choice until after demo! Workitemstore can't find iteration sometime otherwise... // System.Threading.Thread.Sleep(10000); return css.GetNode(newPathUri); }then createWorkItem:private bool createWorkItem(WorkItemStore store, string title, string description, string discipline, string estimateId, string iterationPath) { try { WorkItemType wiType = store.Projects[tfsProject].WorkItemTypes[tfsWorkItemType]; WorkItem newWI = new WorkItem(wiType); newWI.Title = title; newWI.Description = description; newWI.Fields["Microsoft.VSTS.Common.Discipline"].Value = discipline; newWI.Fields["Custom.Office"].Value = "Melbourne"; newWI.Fields["Custom.EstimateId"].Value = estimateId; newWI.Fields["Custom.Risk"].Value = "Low"; newWI.IterationPath = tfsProject + iterationPath; newWI.Save(); return true; } catch (Exception ex) { // return false; throw ex; } }and the actual error is:TF26202: Iteration Path is not a valid area or iteration path. In the Team menu, click Team Project Settings, and then click Areas and Iterations to review the valid area and iteration paths.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException: TF26202: Iteration Path is not a valid area or iteration path. In the Team menu, click Team Project Settings, and then click Areas and Iterations to review the valid area and iteration paths.
Source Error:
Line 173: { Line 174: // return false; Line 175: throw ex; Line 176: } Line 177:Of interest, it only seems to happen on the second time when you submit a form - something is caching somewhere...Thanks for any advice! I'll have to keep my sleep in until I can get this resolved properly as I have a demo today :)Cheers Kolchy! -
Tuesday, February 09, 2010 6:31 PMDid you ever find a fix for this? I've been trying to figure this out for way too long. I have the same issue with AreaPaths. No amount of refreshing, syncing, etc... helps.
-
Monday, May 17, 2010 9:00 AMSolution anyone?
-
Thursday, May 20, 2010 1:42 AM
Hello,
It takes some time for the data from the Integration tables(CSS data) to sync down into Work Item Tracking tables.
You can call directly an API to do this instead of waiting for the job to sync eventually.
So create the new CSS node as above
Call sync WorkItemStore.ClientService.SyncExternalStructures(..)
Continue with creating WI with the new node.
Hope it helps.
Smitha Saligrama MSFT -
Thursday, May 20, 2010 6:55 PM
Hi Smitha,
Sorry. neither the instance of or class WorkItemStore as anything by the name of ClientService. You are referring to TFS2010 version yes?
-Keynan
-
Thursday, May 20, 2010 10:43 PM
That is internal. Sorry about that. You can initialize the Work Item Web services and get the function as below.
using Microsoft.TeamFoundation.WorkItemTracking.Proxy;
var srv = new TeamFoundationServer(tfsServerName);
WorkItemServer witProxy = (WorkItemServer)srv.GetService(typeof(WorkItemServer));ICommonStructureService css = (ICommonStructureService)srv.GetService(typeof(ICommonStructureService));
ProjectInfo projInfo = css.GetProjectFromName("Proj1");
witProxy.SyncExternalStructures(WorkItemServer.NewRequestId(), projInfo.Uri);
Smitha Saligrama MSFT- Proposed As Answer by Keynan Friday, May 21, 2010 7:58 PM
-
Friday, May 21, 2010 7:57 PM
Thanks Smitha,
That solved the problem. It just needs a call to workItemStore.RefreashCache() after.
Here's some code for anyone else with this problem:
[TestMethod] public void testDebug() { WorkItemStore store = tfs.GetService<WorkItemStore>(); ICommonStructureService css = tfs.GetService<ICommonStructureService>(); NodeInfo parentNode = css.GetNodeFromPath("\\APSyncTest\\Iteration"); WorkItem item = store.GetWorkItem(31); String nodeURI = null; try { nodeURI = css.CreateNode("aNode", parentNode.Uri); WorkItemServer server = tfs.GetService<WorkItemServer>(); server.SyncExternalStructures(WorkItemServer.NewRequestId(), css.GetProjectFromName("APSyncTest").Uri); store.RefreshCache(); item.Save(); item.IterationPath = "APSyncTest\\aNode"; item.Save(); } finally { if(nodeURI != null) css.DeleteBranches(new string[] { nodeURI }, parentNode.Uri); } }- Proposed As Answer by Keynan Friday, May 21, 2010 7:58 PM
-
Friday, October 15, 2010 10:15 AM
I met the same issue and looks like all these sync function does not work.
The code Keynan works just because it call workItem.Save() before set the path value. I am still looking for the way do not call that to make the workItem.Field["Area Path"].IsValid = true.
Any hints are appreciated.

