Reputation: 21
I'm stuck with this exception "The given key was not present in the dictionary" which indicates that some value was not found in the dictionary, but the strange thing is I'm not using any dictionary, I guess it is some internal code of the TFS API of C#. Here is the part of the code raising the exception :
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();
This code is a part of loop, where I get the work item, perform some updates using the TFS API, after that, I change the read-only fields directly on the database using the method SubmitChangesToDatabase. The exception is raised when invoking the method Open(). The stack trace is as follows :
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:
Upvotes: 0
Views: 440
Reputation: 23444
I have had this before when my Team Project is configured to use Team Field instead of Aeea Path. If you changed this and some of the work items do not yet have a Team specified then you will get this error.
If you create a query with "yourteamfield.team" set to empty and bulk update all of the work items to have a value the error should go away.
Upvotes: 0