workitem.open() KeyNotFoundException TFS 2013
Posted
技术标签:
【中文标题】workitem.open() KeyNotFoundException TFS 2013【英文标题】: 【发布时间】:2014-06-27 15:50:27 【问题描述】:我遇到了这个异常“字典中不存在给定的键”,这表明字典中没有找到某些值,但奇怪的是我没有使用任何字典,我猜是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:
【问题讨论】:
【参考方案1】:当我的团队项目配置为使用团队字段而不是 Aeea 路径时,我曾经遇到过这种情况。如果您更改了此设置并且某些工作项尚未指定团队,那么您将收到此错误。
如果您创建一个将“yourteamfield.team”设置为空的查询并批量更新所有工作项以具有值,则错误应该会消失。
【讨论】:
谢谢 MrHinsh,但我的问题出在代码的其他地方,我发现更改没有写入数据库,这就是发生异常的原因!以上是关于workitem.open() KeyNotFoundException TFS 2013的主要内容,如果未能解决你的问题,请参考以下文章