I’m working with an EF 4.0 Entity with a property LanguageCode of type String, which is a two-letter language code such as DE or EN. There is a referencial constraint and a Language navigation property as well, but the Language entity set is not included.
I’d like to simply set the language code without loading the Language entity. However, the setter throws an ArgumentOutOfRangeException. More precisely, ReportPropertyChanges method in the setter does:
OnLanguageCodeChanging(value);
ReportPropertyChanging("LanguageCode");
_LanguageCode = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("LanguageCode"); // ArgumentOutOfRangeException
OnLanguageCodeChanged();
The ParamName is not value, but rowIndex. That’s weird, isn’t it?
Google’ing the issue took me to Apparent Breaking Change in Framework 4 (MSDN social). The issue looked similar, but there is no solution. Any faint idea would be very cool… 🙂
The entity is bound in a Windows Forms application. I tried to reproduce the behaviour in a little demo application, but unfortunately I failed. Maybe the issue is not with the entities themselves?
Edit: Here is the stack trace of the exception (including external code):
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.GetCellDisplayRectangle(int columnIndex, int rowIndex, bool cutOverflow) + 0x3f2 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.GetCellAdjustedDisplayRectangle(int columnIndex, int rowIndex, bool cutOverflow) + 0x3f bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.InvalidateCellPrivate(int columnIndex, int rowIndex) + 0x42 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnCellCommonChange(int columnIndex, int rowIndex) + 0x59 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(System.ComponentModel.ListChangedEventArgs e) + 0x7dc bytes
System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e = {System.ComponentModel.ListChangedEventArgs}) + 0x43 bytes
System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.List_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e) + 0x7ec bytes
> DataAccessLayer.dll!DataAccessLayer.Profiles.LanguageCode.set(string value = "DE") Line 13029 + 0x21 bytes C#
The
List<T>was bound to aBindingList. Both aDataGridand some text boxes for a detail view were bound to it. When I added a new item, theDataGridwas not notified (asList<T>does not implementIBindingList).The record was not added to the grid yet, so the Windows Forms’ binding magic tried to update a cell that was not there.
I solved it like this:
(I found the issue thanks to a hint in the comments.)