Index out of range exception at PostFieldValueSetAction()

Posts   
 
    
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 03-May-2006 06:50:33   

I do some calculation when user remove a related child entity from interface, the same coding works fine with v1, it threw the following exception in v2.


QuotationDetails.EntityRemoved += new EventHandler<CollectionChangedEventArgs>(QuotationDetails_EntityRemoved);

void QuotationDetails_EntityRemoved(object sender, CollectionChangedEventArgs e)
{
    QuotationDetailEntity detail = (QuotationDetailEntity)e.InvolvedEntity;
    if (detail.PriceAmt.HasValue) TotPriceAmt -= detail.PriceAmt.Value;
    if (detail.ExtPrice.HasValue) TotExtPrice -= detail.ExtPrice.Value;
    if (detail.LdiscAmt.HasValue) TotLdiscAmt -= detail.LdiscAmt.Value;
    if (detail.NetItemAmt.HasValue) TotItemAmt -= detail.NetItemAmt.Value;
    SummarizeOrderTotal();
}

public override bool SetNewFieldValue(int fieldIndex, object value)
{
    bool toReturn = base.SetNewFieldValue (fieldIndex, value, false);
    if(toReturn && Enum.IsDefined(typeof(QuotationFieldIndex), fieldIndex))
    {
        switch((QuotationFieldIndex)fieldIndex)
        {
            default:
                break;
        }
        base.PostFieldValueSetAction(toReturn, this.Fields[fieldIndex].Name);
    }
    return toReturn;
}

Index was out of range. Must be non-negative and less than the size of the collection.
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.get_Item(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.GetEntityAtIndex(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.get_Item(Int32 index)
   at System.Windows.Forms.BindingSource.get_Item(Int32 index)
   at System.Windows.Forms.CurrencyManager.OnCurrentChanged(EventArgs e)
   at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
   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.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.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.InnerList_ListChanged(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 SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.OnPropertyChanged(String propertyName)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.PostFieldValueSetAction(Boolean fieldValueSet, String propertyName)
   at Test.EntityClasses.QuotationEntity.SetNewFieldValue(Int32 fieldIndex, Object value)
   at Test.EntityClasses.QuotationEntity.set_TotPriceAmt(Nullable`1 value)
   at Test.EntityClasses.QuotationEntity.QuotationDetails_EntityRemoved(Object sender, CollectionChangedEventArgs e)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.OnEntityRemoved(T entityToRemove)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.RemoveAt(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.RemoveAt(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.RemoveAt(Int32 index)
   at System.Windows.Forms.BindingSource.RemoveAt(Int32 index)
   at System.Windows.Forms.CurrencyManager.RemoveAt(Int32 index)
   at Infragistics.Win.UltraWinGrid.UltraGridRow.DeleteHelper()
   at Infragistics.Win.UltraWinGrid.UltraGridLayout.InternalDeleteRowsHelper(SelectedRowsCollection Rows, Boolean displayPrompt)
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.get_Item(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.GetEntityAtIndex(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.get_Item(Int32 index)
   at System.Windows.Forms.BindingSource.get_Item(Int32 index)
   at System.Windows.Forms.CurrencyManager.OnCurrentChanged(EventArgs e)
   at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)
   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.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.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.InnerList_ListChanged(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 SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.OnPropertyChanged(String propertyName)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.PostFieldValueSetAction(Boolean fieldValueSet, String propertyName)
   at Test.EntityClasses.QuotationEntity.SetNewFieldValue(Int32 fieldIndex, Object value)
   at Test.EntityClasses.QuotationEntity.set_TotPriceAmt(Nullable`1 value)
   at Test.EntityClasses.QuotationEntity.QuotationDetails_EntityRemoved(Object sender, CollectionChangedEventArgs e)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.OnEntityRemoved(T entityToRemove)
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.RemoveAt(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.RemoveAt(Int32 index)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.RemoveAt(Int32 index)
   at System.Windows.Forms.BindingSource.RemoveAt(Int32 index)
   at System.Windows.Forms.CurrencyManager.RemoveAt(Int32 index)
   at Infragistics.Win.UltraWinGrid.UltraGridRow.DeleteHelper()
   at Infragistics.Win.UltraWinGrid.UltraGridLayout.InternalDeleteRowsHelper(SelectedRowsCollection Rows, Boolean displayPrompt)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 03-May-2006 08:52:18   

I closed this thread as I thought it was a duplicate, however I can't find the duplicate now so I re-open the thread.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 06-May-2006 09:15:51   

I need more info about when it happens, the code you execute etc. Please add that information.

Frans Bouma | Lead developer LLBLGen Pro
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 06-May-2006 10:32:07   

I've tried to create a sample application for you to reproduce the problem, I copied the same coding to it, but it does not have this exception in the sample application, so strange.

I've moved my code form EntityRemoved event to EntityRemoving event, it does not have any problems at PostFieldValueSetAction() now. confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 06-May-2006 10:58:56   

Be aware that EntityRemoved is raised AFTER the entity has been removed. What I want to know is what the context is: so is the collection a contained collection in an entity? (Customer.Orders) What do you do in SummarizeOrderTotal exactly?

What I need is info to reproduce it here or at least to get myself a clear image what the problem domain is so I can think more broader and spot other situations where it might occur as well.

The events can lead you into a mess, the same is true with grids which update datastructures which raise events when they're changed so you will update the grid and that then causes problems etc. etc.

Frans Bouma | Lead developer LLBLGen Pro
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 06-May-2006 11:47:30   

The entity is removed from collection, and exception is thrown at the line second line, TotPriceAmt -= detail.PriceAmt.Value.

I trace it in debugger, the value (TotPriceAmt) in parent entity is already updated to field correctly at base.SetNewFieldValue(), and exception thrown at the line base.PostFieldValueSetAction();

I don't know what PostFieldValueSetAction() do exactly, maybe I compile a debug build of runtime dll today later and trace which line thrown exception exactly inside PostFieldValueSetAction().

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 06-May-2006 11:51:08   

PostFieldValueSetAction is the method which raises the field changed event. It's used from the setnewfieldvalue method, after the FK dereferences are done. The setnewfieldvalue action likely occurs due to the desync of a related entity.

So for me to be able to reproduce it, I need the entity setup (e.g. customer with an orders collection, you remove an order, hell breaks loose, that kind of stuff wink ) so I can reproduce it here. With events it's very hard to track down the problems if the correct setup isn't used, as the problems are often very related to a given situation.

Also where is the routine located? Inside another entity? Please, if possible, give me more information, sorry for nagging, but I know these bugs are the ones that are really needed to get fixed if present...

Frans Bouma | Lead developer LLBLGen Pro
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 06-May-2006 16:41:46   

I finally created a sample application for you to reproduce this issue, please check mail. Thank you very much!!!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 06-May-2006 17:23:02   

Received it, many thanks! simple_smile . I'll check it out.

Frans Bouma | Lead developer LLBLGen Pro
Boone
User
Posts: 22
Joined: 21-Feb-2008
# Posted on: 21-Feb-2008 10:45:47   

What was the conclusion on this issue? I'm running into the same exception in a similiar manner.

I have a SalesOrderEntity with many SalesOrderDetailEntity's. In OnInitialized I attach to the SalesOrderDetailCollection's ListChangedEventHandler. In that event handler I call OnPropertyChanged("SubTotal") to signal the GUI to reload the SubTotal, which is a simple property that sums up the Detail amounts.

When I remove a SalesOrderDetailEntity from the SalesOrderEntity's SalesOrderDetailCollection, the call to OnPropertyChanged results in the ArgumentOutOfRangeException. Even changing it to OnPropertyChanged("nonexistentproperty") results in the exception.

The stack trace looks near identical after the OnPropertyChanged call as above so I'm hoping whatever the solution to Barry's problem will solve my issue as well, otherwise let me know if more information would help or if I should attempt to create an example project with this error.

Since this is my first post, I should say that I'm loving LLBLGen Pro, what a wonderful tool!! Thanks Otis simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 21-Feb-2008 11:23:11   

Is this v.2.5?

I prefer that you post your own stack trace simple_smile

Anyway would you please post a repro solution on Northwind? And please post the runtime library version you are using.

Since this is my first post, I should say that I'm loving LLBLGen Pro, what a wonderful tool!! Thanks Otis

Thanks and welcome aboard, next time please create a new thread. simple_smile