StrataFrame Forum

Specified key was not present in the dictionary

http://forum.strataframe.net/Topic11037.aspx

By Andria Jensen - 8/23/2007

I have a DevExpress grid which I have bound to a BusinessBindingSource pointing to a Business Object.  The grid is editable, and has a couple of dropdowns in it.  When I try to select from the drop downs or enter into the other fields I am getting the error message:

Unexpected Error in MicroFour StrataFrame Base
The specified key was not present in the dictionary.

What does this error really mean in this case?  I'm just not sure where to start looking for the problem to debug it.

By StrataFrame Team - 8/24/2007

Hrm, it could be that the property descriptor for that bound column is not registered.  Does the grid have an Error event or something that you could handle?  If it has an Error or DataError event or whatnot, it should give you the raw exception... if I had the stack trace, I could probably give you more information.  That message is the message thrown by the .NET generics Dictionar<,>, and we use those everywhere.
By Andria Jensen - 8/24/2007

The stack trace is as follows:

8/23/2007 3:33:47 PM
Source: MicroFour StrataFrame Base
Message: The specified key was not present in the dictionary.
Stack:    at MicroFour.StrataFrame.Data.DataBasics.GetFieldFromDictionaryOrdinalKey[T](Dictionary`2 dict, String key)
   at MicroFour.StrataFrame.Data.DataBasics.InitializeNewRow(DataRow NewDataRow, StringCollection IgnoredFields, Dictionary`2 FieldNativeTypes)
   at MicroFour.StrataFrame.Business.BusinessLayer.NewRow()
   at MicroFour.StrataFrame.Business.BusinessLayer.Add(Boolean CheckSecurity)
   at MicroFour.StrataFrame.Business.BusinessBindingSource.IBindingListView_AddNew()
   at System.Windows.Forms.CurrencyManager.AddNew()
   at DevExpress.Data.CurrencyDataController.AddNewRow()
   at DevExpress.XtraGrid.Views.Grid.GridView.OnActiveEditor_ValueModified(Object sender, EventArgs e)
   at DevExpress.XtraEditors.Repository.RepositoryItem.RaiseModified(EventArgs e)
   at DevExpress.XtraEditors.BaseEdit.RaiseModified()
   at DevExpress.XtraEditors.BaseEdit.set_IsModified(Boolean value)
   at DevExpress.XtraEditors.BaseEdit.OnEditValueChanging(ChangingEventArgs e)
   at DevExpress.XtraEditors.BaseEdit.set_EditValue(Object value)
   at DevExpress.XtraEditors.ComboBoxEdit.set_EditValue(Object value)
   at DevExpress.XtraEditors.PopupBaseEdit.AcceptPopupValue(Object val)
   at DevExpress.XtraEditors.PopupBaseEdit.DoClosePopup(PopupCloseMode closeMode)
   at DevExpress.XtraEditors.PopupBaseEdit.ClosePopup(PopupCloseMode closeMode)
   at DevExpress.XtraEditors.PopupBaseEdit.ClosePopup()
   at DevExpress.XtraEditors.Popup.PopupListBox.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

By StrataFrame Team - 8/27/2007

Hrm, in this case, it means that the business object it trying to add a new row and initialize the fields in that row, however, the shared collections in the business object containing information on the fields and how to initilize them does not match the columns that are in the table.  Looking at the source code, it might be that you have an extra column in the business object that is not part of the actual table.  And it looks like it will most likely be a DateTime column because that GetFieldFromDictionaryOrdinalKey method is only called when the column's type is DateTime.