Strange error after upgrading from 2 to 2.5

Posts   
 
    
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 11-Nov-2007 15:38:23   

Hello,

I had a LLBL 2.0 self-servicing project which I upgraded to LLBL 2.5 (22/10/2007). I'm suddenly hit with a strange error in code that used to work fine before.

The error is: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

This happens when I run the following code:

        Private Sub entityDetail_EntityAdding(ByVal sender As Object, ByVal e As CancelableCollectionChangedEventArgs)

        Dim x As BranchSaleDetailEntity = CType(e.InvolvedEntity, BranchSaleDetailEntity)

        With x
            .IntSort = Me.CurrentEntity.IntMaxLineNoDetail + 1
            .IntLineNo = .IntSort
            .DecDiscount = 0
            .DecCostPrice = 0
            .DecQty = 1
            .DecSalesPrice = 0

            Me.CurrentEntity.IntMaxLineNoDetail += 1
        End With

    End Sub

which fires:

        Public Overridable Property [IntMaxLineNoDetail]() As System.Int32
            Get
                Return CType(GetValue(CInt(BranchSaleFieldIndex.IntMaxLineNoDetail), True), System.Int32)
            End Get
            Set
                Error fires here===>SetValue(CInt(BranchSaleFieldIndex.IntMaxLineNoDetail), value, True)
            End Set
        End Property

What's wrong?

If you need the stack trace let me know. Thanks!

Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 11-Nov-2007 15:43:41   

By the way, the 'Me.CurrentEntity' in the above code refers to a 'BranchSaleEntity' which is the parent entity for the 'BranchSaleDetailEntity' on a one-to-many relationship. Think of it as InvoiceHeader and InvoiceDetail.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Nov-2007 05:23:20   

Hi Bashar ,

Indeed, the stackTrace would be helpful wink Are you using MultiSelect Property set to False or True? Are you using comboboxes in your grid?

I remember this error happened to me, but I can't reproduce now disappointed , and for me it wasn't related to LLBL cross version.

Is this link (https://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=119366) useful in your case?

David Elizondo | LLBLGen Support Team
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 12-Nov-2007 08:36:13   

Hi! Thank you for you reply.

"   at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.MatchCurrencyManagerPosition(Boolean scrollIntoView, Boolean clearSelection)
   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.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.SetList(IList list, Boolean metaDataChanged, Boolean applySortAndFilter)
   at System.Windows.Forms.BindingSource.ParentCurrencyManager_CurrentItemChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.CurrencyManager.OnCurrentItemChanged(EventArgs 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.ListItem_PropertyChanged(Object sender, EventArgs e)
   at System.ComponentModel.PropertyDescriptor.OnValueChanged(Object component, EventArgs e)
   at System.ComponentModel.ReflectPropertyDescriptor.OnValueChanged(Object component, EventArgs e)
   at System.ComponentModel.ReflectPropertyDescriptor.OnINotifyPropertyChanged(Object component, PropertyChangedEventArgs e)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.OnPropertyChanged(String propertyName)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.PostFieldValueSetAction(Boolean fieldValueSet, String propertyName)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.SetValue(Int32 fieldIndex, Object value, Boolean checkForRefetch, Boolean performDesyncForFKFields)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.SetValue(Int32 fieldIndex, Object value, Boolean checkForRefetch)
   at Jebus.InventoryControl.DAL.EntityClasses.BranchSaleEntityBase.set_IntMaxLineNoDetail(Int32 Value) in D:\Documents and Settings\bashar\My Documents\Development\SharqStarHO\DAL\EntityBaseClasses\BranchSaleEntityBase.vb:line 977
   at Jebus.InventoryControl.Windows.frmBranchSale.entityDetail_EntityAdding(Object sender, CancelableCollectionChangedEventArgs e) in D:\Documents and Settings\bashar\My Documents\Development\SharqStarHO\Windows\Menu\Transactions\Branch\frmBranchSale.vb:line 809
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.OnEntityAdding(T entityToAdd)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.PerformAdd(T item)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Add(T item)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase`1.AddNew()
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.AddNew()
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.ComponentModel.IBindingList.AddNew()
   at System.Windows.Forms.BindingSource.AddNew()
   at System.Windows.Forms.CurrencyManager.AddNew()
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded()
   at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
   at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
   at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
   at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
   at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)"
Me.dgvBranchSaleDetail.MultiSelect = False

Comboboxes in the grid, yes! The link provided is helpful, however I'm still facing the same problem. cry

Any more suggestions.

Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 12-Nov-2007 08:39:26   

By the way, the problem occurs ONLY when I refer to the parent entity of the grid line entity. If not then there is no problem whatsoever.

Does that help?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Nov-2007 10:25:17   

By the way, the problem occurs ONLY when I refer to the parent entity of the grid line entity. If not then there is no problem whatsoever

Would you please elaborate more in this line? What exactly do you mean by "refer to the parent entity of the grid line entity"?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Nov-2007 11:32:13   

The field you're setting which triggers the error, is that an FK field? (so a related entity is reset by setting that field). What I find strange is that this apparently is a problem with the grid. It might be related to the position where the code is located (in the editing event handler), but I'm not sure. I think what the reason is is that you're editing line X, and due to that line, line X has to be refreshed due to an event that was raised, however that can't be as it's in edit mode, so the grid gives up. (I think that's what happened)

Frans Bouma | Lead developer LLBLGen Pro
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 12-Nov-2007 11:58:06   

Walaa, as I mentioned earlier in the thread, I'm modifying a property in the invoice header entity when we add a new entity in the child entity collection (invoice detail). Modifying the parent entity triggers the error.

Frans, this was NOT a problem when I was using LLBL v2.0. And no, the field being set is NOT a FK, PK or in any way related to any other field. When I comment out the line that causes the error, the code runs fine.

Should I revert back to v2.0?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Nov-2007 13:15:04   

Bashar wrote:

Walaa, as I mentioned earlier in the thread, I'm modifying a property in the invoice header entity when we add a new entity in the child entity collection (invoice detail). Modifying the parent entity triggers the error.

Frans, this was NOT a problem when I was using LLBL v2.0. And no, the field being set is NOT a FK, PK or in any way related to any other field. When I comment out the line that causes the error, the code runs fine.

Should I revert back to v2.0?

Reverting back shouldn't be an option, it has a reason so it can be fixed.

I think I found a way for you to stop this from happening. The parent entity is in a collection, correct? This collection is bound to the form?

Ok, if so, use this: - grab the default view from the collection - set its RaisesItemChangedEvents to true - bind the default view instead of the collection to a BindingSource and bind that to the gridview.

It now should be the case that the error goes away. You will however see that changing a property in the parent entities won't be reflected in the grid. So you probably need to toggle this.

It's a bit tricky, but it's a matter of working around the magic code called 'currencymanager' that's living in the form. Databinding can do a lot for you, but if events are raised all over the place (more events are raised than in v2.0), it can get confused.

Frans Bouma | Lead developer LLBLGen Pro
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 13-Nov-2007 16:31:00   

Why do I have to do all that (as logical as it may sound)? Cannot things simply work the same way they used to work under v2.0?

Also, when handling the 'EntityAdding' and 'EntityRemoving' events of a child collection bound to a datagridview, I noticed that when the user adds a new entity to the grid in runtime the event(s) gets fired twice. Is this normal? I hope not, this was not the case in v2 as well.

Thanks for all your help on this, I really appreciate it. smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 13-Nov-2007 18:32:53   

Bashar wrote:

Why do I have to do all that (as logical as it may sound)? Cannot things simply work the same way they used to work under v2.0?

Because it actually didn't work under v2.0. Several key events weren't propagated upwards in v2.0, so you didn't ran into this under v2.0. In v2.5 these events ARE propagated upwards. What happens is that an entity field in the parent gets changed and notifies this to its container (collection) via PropertyChanged. The flag I discussed in my previous post prevents this event from being bubbled upwards to the collection which would make the collection raise a ListChanged event for the position the entity is in. This didn't always happen in v2.0.

Because the events now do work properly, this could lead to more events than you want, and for example a grid go bezerk. The flag is there to prevent this. That's all we can do really, because it's a choice between a rock and a hard place.

Also, when handling the 'EntityAdding' and 'EntityRemoving' events of a child collection bound to a datagridview, I noticed that when the user adds a new entity to the grid in runtime the event(s) gets fired twice. Is this normal? I hope not, this was not the case in v2 as well.

Thanks for all your help on this, I really appreciate it. smile

Grids aren't really the greatest tools to test this, as often events are raised twice. EntityAdding is raised from within the collection. When you arrive in the handler routine, do you see the same Call stack in the debugger? (which would show 2 times a binding to same event)

Frans Bouma | Lead developer LLBLGen Pro