BindingSource.EndEdit() throws Exception

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Environment Information:
I am running Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600) and
connecting to a SQL Server 2005 database, although this problem never reaches
the database. I am also using Windows XP Professional SP 2.

My problem is that when I call the EndEdit() method for my BindingSource, I
recieve the following error:

System.ArgumentNullException: Value cannot be null.
Parameter name: key
Stack Trace: at
System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Data.DataView.MaintainDataView(ListChangedType changedType,
DataRow row, Boolean trackAddRemove)
at System.Data.DataViewListener.MaintainDataView(ListChangedType
changedType, DataRow row, Boolean trackAddRemove)
at
System.Data.Index.<>c__DisplayClass5.<MaintainDataView>b__4(DataViewListener
listener, ListChangedType type, DataRow row, Boolean track)
at System.Data.Listeners`1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3,
Action`4 action)
at System.Data.Index.MaintainDataView(ListChangedType changedType, Int32
record, Boolean trackAddRemove)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32
changeRecord)
at System.Data.DataTable.RecordStateChanged(Int32 record1,
DataViewRowState oldState1, DataViewRowState newState1, Int32 record2,
DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32
proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position,
Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32
pos, Boolean fireEvent)
at System.Data.DataView.FinishAddNew(Boolean success)
at System.Data.DataRowView.EndEdit()
at System.Windows.Forms.CurrencyManager.EndCurrentEdit()
at System.Windows.Forms.BindingSource.EndEdit()

There is a BindingNavigator and DateTimePicker control bound to the
BindingSource. The BindingSource is bound to a TableAdapter on a DataSet.
The DateTimePicker is not likely to be a part of the problem because I also
tried replacing it with a regular TextBox and the error still occurred.

This problem occurs randomly. The application passed all testing and the
error did not appear until the application was deployed. The error happens
more often than not, but it does not always happen even using the EXACT same
steps to create the issue.

Please help! If you would like more details on how specific objects are
bound, please let me know.

Thanks!
 
It fails in both Release and Debug mode. The application passed all of the
testing in March. It began to be used last week which is when we came across
the error which makes me suspect that a Windows Update might be part of the
problem especially if any new updates contained updates to the .NET framework.

I do not actually use a Dictionary myself, rather from the stack trace, it
appears to be internally used in Microsoft's DataView object.

Basically, I have a form that has a UserControl on it. The UserControl
contains a DataSet, a BindingSource with a filter bound to that DataSet, a
BindingNavigator to navigate sets of records, and a DateTimePicker set to
show only time so the user can modify times in the DataSet. If you need more
detailed information to recreate the problem, please let me know.

Also, I have checked the values in the BindingSource using the Watch window
before the EndEdit method is called and the (BindingSource.Current as
DataRowView)["DateTimeField"] is equal to the expected value. Of course, I
had to loop through the Bindings object of the CurrencyManager for the
BindingSource and call WriteValue() on each Binding so the value from the
DateTimePicker is written to the BindingSource, but it should work fine.

I have other UserControls with the same kind of objects performing similar
operations.
The only noticiable difference between them is that this BindingSource has a
Filter on it.

To recreate the issue from the user perspective, here are the steps:
1. The user clicks the Add Button on the BindingNavigator. This sets focus
to the DateTimePicker allowing the user to enter a valid time.
2. The user enters the time and clicks Save which internally calls
Binding.WriteValue() for each binding and then calls BindingSource.EndEdit()
which throws the error as shown in my previous post.

Any help would be greately appreciated as I am under the gun to get this
issue resolved.

Thanks!
Aaron

RobinS said:
As far as it only working when it is deployed, try running it in release
mode from Visual Studio and see if you can recreate it.

It sounds like you have a value in your row that is null and it is not
allowed to be. Are you binding a dictionary to something, or using a
dictionary for a combobox?

RobinS.
GoldMail.com
--------------------------------------------
Aaron said:
Environment Information:
I am running Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600) and
connecting to a SQL Server 2005 database, although this problem never
reaches
the database. I am also using Windows XP Professional SP 2.

My problem is that when I call the EndEdit() method for my BindingSource,
I
recieve the following error:

System.ArgumentNullException: Value cannot be null.
Parameter name: key
Stack Trace: at
System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Data.DataView.MaintainDataView(ListChangedType changedType,
DataRow row, Boolean trackAddRemove)
at System.Data.DataViewListener.MaintainDataView(ListChangedType
changedType, DataRow row, Boolean trackAddRemove)
at
System.Data.Index.<>c__DisplayClass5.<MaintainDataView>b__4(DataViewListener
listener, ListChangedType type, DataRow row, Boolean track)
at System.Data.Listeners`1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3,
Action`4 action)
at System.Data.Index.MaintainDataView(ListChangedType changedType, Int32
record, Boolean trackAddRemove)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32
changeRecord)
at System.Data.DataTable.RecordStateChanged(Int32 record1,
DataViewRowState oldState1, DataViewRowState newState1, Int32 record2,
DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32
proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position,
Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32
pos, Boolean fireEvent)
at System.Data.DataView.FinishAddNew(Boolean success)
at System.Data.DataRowView.EndEdit()
at System.Windows.Forms.CurrencyManager.EndCurrentEdit()
at System.Windows.Forms.BindingSource.EndEdit()

There is a BindingNavigator and DateTimePicker control bound to the
BindingSource. The BindingSource is bound to a TableAdapter on a DataSet.
The DateTimePicker is not likely to be a part of the problem because I
also
tried replacing it with a regular TextBox and the error still occurred.

This problem occurs randomly. The application passed all testing and the
error did not appear until the application was deployed. The error
happens
more often than not, but it does not always happen even using the EXACT
same
steps to create the issue.

Please help! If you would like more details on how specific objects are
bound, please let me know.

Thanks!
 
Hi!

I've got a similar problem, only my call stack is a little different
at the beginning:
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument
argument)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Data.DataView.MaintainDataView(ListChangedType
changedType, DataRow row, Boolean trackAddRemove)
at System.Data.DataViewListener.MaintainDataView(ListChangedType
changedType, DataRow row, Boolean trackAddRemove)
at
System.Data.Index.<>c__DisplayClass5.<MaintainDataView>b__4(DataViewListener
listener, ListChangedType type, DataRow row, Boolean track)
at System.Data.Listeners`1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3
arg3, Action`4 action)
at System.Data.Index.MaintainDataView(ListChangedType changedType,
Int32 record, Boolean trackAddRemove)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action,
Int32 changeRecord)
at System.Data.DataTable.RecordStateChanged(Int32 record1,
DataViewRowState oldState1, DataViewRowState newState1, Int32 record2,
DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32
proposedRecord, DataRowAction action, Boolean isInMerge, Int32
position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID,
Int32 pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(DataRow row)

I am simply inserting a (recently created) new row in my datatable -
schematically:
DataRow dr = MyDT.NewRow;
dr.SomeFields = SomeValues;
MyDT.Add(dr);
The problem is also happening randomly (but more than often enough for
our customers).

I have used Reflector to track the problem down a bit, and I do
believe that this is a case overlooked by the MS developers:
The reverse engineered code for DataView.MaintainDataView has only one
call to Dictionary[], so the only parameter it can complain about
being null, is addNewRow.
This can only happen when the row passed to MaintainDataView is also
null (in that case row == this.addNewRow returns true).
Tracking down the rest might take too long, but perhaps some MS
employee can pick it up from here?

For the record: we are not using multithreading in our code (well,
nowhere near the relevant DataTable), so this should not cause this to
happen.
It seems (as ever so often) that the underlying logic with oldRecord,
newRecord and tempRecord is simply failing again...

Any more inputs?

Nick.
 
Back
Top