none
Apparent Breaking Change in Framework 4 RRS feed

  • Question

  • This worked very well on Framework 3.5. Now on Framework 4 I get an error in the designer-generated L2S code:

    "Specified argument was out of the range of valid values.
    Parameter name: rowIndex"

    It's occurring in the SendPropertyChanged() method, which is passing the value "Invoice" in the propertyName parameter.

    I'm not finding any rowIndex variable anywhere, nor am I finding anywhere in the generated code such an error might orginate. Reflector doesn't reveal much that's useful in the System.Data.Linq namespace.

    Here's a quick demo of the code that used to work:

    Public Class AddPaymentDemo
    
     Private WithEvents PaymentsBinding As New BindingList(Of Db.Payment)
     Private DbContext As Db.MatrixContext
     Private Invoice As Db.Invoice
    
     Public Sub New(ByVal InvoiceId As Integer)
     AddHandler Me.PaymentsBinding.ListChanged, AddressOf Me.PaymentsBinding_ListChanged
     Me.Invoice = Me.DbContext.Invoices.Single(Function(I) I.InvoiceId = InvoiceId)
     End Sub
    
     Public Sub AddPayment()
     Me.PaymentsBinding.Add(New Db.Payment)
     End Sub
    
     Private Sub PaymentsBinding_ListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs)
     If e.ListChangedType = ListChangedType.ItemAdded Then
      Me.Invoice.Payments.Add(Me.PaymentsBinding(e.NewIndex))
     End If
     End Sub
    
     Protected Overrides Sub Finalize()
     MyBase.Finalize()
     RemoveHandler Me.PaymentsBinding.ListChanged, AddressOf Me.PaymentsBinding_ListChanged
     End Sub
    End Class
    

    The AddPayment() method gets us started.

    Is this something that's changed that now requires a different approach?

     

    Thanks,
    Jeff

     

    • Edited by InteXX Monday, September 6, 2010 9:05 AM Text Cleanup
    Monday, September 6, 2010 9:01 AM

All replies

  • Can you post the stack trace here so we can see which routine is looking for rowIndex?

    Thanks,

    [)amien

    Monday, September 6, 2010 6:40 PM
    Moderator
  • Hi Damien, certainly. The stack trace is below.

    I should point out that my demo code above is incomplete. On a WinForm I'm using the BindingList(Of Db.Payment) technique as illustrated in the last section of this post (Binding to IBindingList and IBindingListView).

    I've been able to temporarily get around the problem by setting BindingSource.DataSource directly to Db.Invoices.Payments and then clearing DataSource and resetting it whenever necessary. This works for now at least—I have to ship this code tonight.

    Thanks,
    Jeff

     

    = Begin Stack Trace ======================================================

       at System.Windows.Forms.DataGridView.InvalidateCell(Int32 columnIndex, Int32 rowIndex)
       at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)
       at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
       at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
       at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
       at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
       at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
       at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e)
       at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
       at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
       at System.ComponentModel.BindingList`1.Child_PropertyChanged(Object sender, PropertyChangedEventArgs e)
       at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
       at Db.Payment.SendPropertyChanged(String propertyName) in D:\AddPaymentDemo\Db\Schemas\Linq\AddPaymentDemo.designer.vb:line 3608
       at Db.Payment.set_Invoice(Invoice Value) in D:\AddPaymentDemo\Db\Schemas\Linq\AddPaymentDemo.designer.vb:line 3589
       at Db.Invoice.attach_Payments(Payment entity) in D:\AddPaymentDemo\Db\Schemas\Linq\AddPaymentDemo.designer.vb:line 1929
       at System.Data.Linq.EntitySet`1.OnAdd(TEntity entity)
       at System.Data.Linq.EntitySet`1.Add(TEntity entity)
       at M.EntityManager.PaymentsBinding_ListChanged(Object sender, ListChangedEventArgs e) in D:\AddPaymentDemo\M\MCommon.vb:line 390
       at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
       at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
       at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
       at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
       at System.Collections.ObjectModel.Collection`1.Add(T item)
       at AddPaymentDemo.Payment.AddPayment() in D:\AddPaymentDemo\Ui\Forms\Payment.vb:line 267
       at AddPaymentDemo.Payment.ApplyChanges() in D:\AddPaymentDemo\Ui\Forms\Payment.vb:line 319
       at AddPaymentDemo.Payment.cmdOkApply_Click(Object sender, EventArgs e) in D:\AddPaymentDemo\Ui\Forms\Payment.vb:line 143
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at AddPaymentDemo.Details.cmdAddPayment_Click(Object sender, EventArgs e) in D:\AddPaymentDemo\Ui\Forms\Details.vb:line 168
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at AddPaymentDemo.Main.ViewDetail() in D:\AddPaymentDemo\Ui\Forms\Main.vb:line 647
       at AddPaymentDemo.Main.dgvSearchResults_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) in D:\AddPaymentDemo\Ui\Forms\Main.vb:line 315
       at System.Windows.Forms.DataGridView.OnCellDoubleClick(DataGridViewCellEventArgs e)
       at System.Windows.Forms.DataGridView.OnDoubleClick(EventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.DataGridView.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at AddPaymentDemo.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

    = End Stack Trace ======================================================

     

    Monday, September 6, 2010 7:22 PM
  • Hello Jeff,

     

    Do you mean you have worked around this issue?   So does the issue still occur if you use the original code logic? 

     

    If you need more support, could you please share us with a repro demo for further investigation?   You can directly ping me at v-micsun@microsoft.com.  

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, September 7, 2010 6:44 AM
    Moderator
  • I may be posting to the wrong forum.

    The VS stack stops at the L2S code, but the Exception Helper stack—which I posted here—shows the true culprit. It's the DataGridView.InvalidateCell() method. The rowIndex parameter apparently contains an unexpected value.

    Now, whether the DataGridView is at fault here—questionable—or L2S/BindingList/BindingSource is sending it the wrong value is unknown.

    The bottom line is that the DataGridView->BindingSource->BindingList(Of T)->L2S stack is broken in Framework 4 when it worked in Framework 3.5.

    My klunky workaround is to eliminate the BindingList(Of Db.Payment) altogether:

    Db.Invoices.Payments.Add(New Db.Payment)
    BindingSource.DataSource = Nothing
    BindingSource.DataSource = Db.Invoices.Payments
    

    Naturally this isn't my preference, but at least it gets the job done.

    I'm under heavy deadline right now, so I'll try to get a working demo to you by the end of the week.

    Thanks,
    Jeff

     

    Tuesday, September 7, 2010 5:03 PM
  • Here is a list of changes from 3.5 to 4.0 in Linq To Sql

    http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40

    Tuesday, September 7, 2010 8:37 PM
  • This is a good list, thanks.

    I don't immediately see anything that addresses this particular issue, but it's a good resource to keep on hand. I'll study it some more when I have time.

    Thanks,
    Jeff

     

    Tuesday, September 7, 2010 8:52 PM
  • Well now this certainly is odd.

    I built up a quick solution to demo this and I was able to reproduce the problem—once. I did a bit of refactoring and suddenly it worked as expected. I returned the code back to its pre-refactor state and it still worked as expected.

    I switched over to my original application—the one where I encountered this in the first place—and I can reproduce the error consistently. I've closely examined the two code bases and they employ the same structure with regard to BindingSource/BindingList.

    I'm stumped.

    Unfortunatly I've run out of time to work on it further. I'm going to have to stick with my workaround until I gut the whole thing and replace it with EF early next year.

    Thanks,
    Jeff

     

    Sunday, September 12, 2010 4:57 AM
  • Hi Jeff,

     

    Is it convenient for you to send me the demo?   I will do my best to help you.   My mail: v-micsun@microsoft.com. 

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, September 14, 2010 2:30 AM
    Moderator
  • Hi Jeff,

     

    Could you please tell us how is the problem now?  

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, September 17, 2010 1:31 AM
    Moderator
  • Hi Lingzhi

    Pardon me for not replying—I missed the email alert for your previous post.

    I've emailed you the demo, such as it is.

    Thanks,
    Jeff

     

    Friday, September 17, 2010 6:52 AM
  • Hi Jeff,

     

    It seems that the problem is solved now.   Can we close the case now?  

    Of course, if you encounter the issue again, feel free to re-open it.  I will do my best to help you.

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, October 1, 2010 1:48 AM
    Moderator