0

我遇到了这个异常“字典中不存在给定的键”,这表明字典中没有找到某些值,但奇怪的是我没有使用任何字典,我猜这是一些内部代码C# 的 TFS API。这是引发异常的代码部分:

if (wi.Validate().Count == 0)
{
     // Save the work item to submit changes
     wi.Save();
}
else
{
     Console.WriteLine("following errors was encountered when trying to save the work          item {0} : ", id);
     foreach (var e in wi.Validate())
                        {
           Console.WriteLine(" - '{0} '", e);
     }
}


                    // Close the work item
                    wi.Close(); 

                    // Submit the changes to the database
                    SubmitChangesToDatabase(id, author, statusChanged, previousChangeTime);  

                    // Open again the work item to go on with other updates
                    wi.Open();

这段代码是循环的一部分,我在其中获取工作项,使用 TFS API 执行一些更新,之后,我使用方法SubmitChangesToDatabase直接在数据库上更改只读字段。调用方法Open()时引发异常。堆栈跟踪如下:

System.Collections.Generic.KeyNotFoundException was unhandled
  HResult=-2146232969
  Message=The given key was not present in the dictionary.
  Source=mscorlib
  StackTrace:
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Microsoft.TeamFoundation.WorkItemTracking.Internals.WorkItemHelper.FindRevisionIndexByDate(Int32 trackTimeFieldId, List`1 revisions, Dictionary`2 latestData, DateTime dt, Int32 startIndex)
       at Microsoft.TeamFoundation.WorkItemTracking.Internals.WorkItemHelper.LoadWorkItemFieldData(IRowSetCollectionHelper tables, IWorkItemOpenFieldDataHelper helper)
       at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.LoadWorkItemFromRowSetInternal(Int32 rev, Nullable`1 asof, IWorkItemRowSets witem)
       at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.LoadWorkItem(Int32 id, Int32 rev, Nullable`1 asof)
       at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.Open()
       at CSVToTFS.TFSServer.SetWorkItemHistory(Int32 id, DataTable ticketChange) in d:\Documents\Visual Studio 2013\Projects\TFS\CSVToTFS\TFSServer.cs:line 253
       at CSVToTFS.Program.Main(String[] args) in d:\Documents\Visual Studio 2013\Projects\TFS\CSVToTFS\Program.cs:line 173
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
4

1 回答 1

0

当我的团队项目被配置为使用团队字段而不是 Aeea 路径时,我曾经有过这种情况。如果您更改了此设置并且某些工作项尚未指定团队,那么您将收到此错误。

如果您创建一个将“yourteamfield.team”设置为空的查询并批量更新所有工作项以具有一个值,则该错误应该会消失。

于 2014-06-29T10:34:18.833 回答