C# workitem.open()KeyNotFoundException TFS 2013
我遇到了这个异常,给定的键在字典中不存在,这表明在字典中找不到某些值,但奇怪的是我没有使用任何字典,我猜这是C的TFS API的一些内部代码。 以下是引发异常的代码部分:C# workitem.open()KeyNotFoundException TFS 2013,c#,tfs,tfs-sdk,first-chance-exception,keynotfoundexception,C#,Tfs,Tfs Sdk,First Chance Exception,Keynotfoundexception,我遇到了这个异常,给定的键在字典中不存在,这表明在字典中找不到某些值,但奇怪的是我没有使用任何字典,我猜这是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
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();
这段代码是循环的一部分,在循环中,我获取工作项,使用TFSAPI执行一些更新,然后,我使用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:
当我的团队项目被配置为使用团队字段而不是Aeea路径时,我曾经遇到过这种情况。如果您对此进行了更改,并且某些工作项尚未指定团队,则会出现此错误
如果将yourteamfield.team设置为空并批量更新所有工作项以使其具有值,则错误应消失。谢谢MrHinsh,但我的问题是代码中的其他地方,我发现更改没有写入数据库,这就是发生异常的原因!