0
我被这个异常卡住了“给定的键不存在于字典中”,这表明在字典中没有找到某个值,但奇怪的是我不是使用任何字典,我想这是C#的TFS API的一些内部代码。 这里是代码的提高例外部分:workitem.open()KeyNotFoundException TFS 2013
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直接在数据库上进行。调用方法打开()时引发异常。 堆栈跟踪如下:
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:
谢谢MrHinsh,但我的问题是在代码的其他地方,我发现变化没有写入数据库,这就是发生异常的原因! –