Print Page | Close Window

ArgumentOutOfRange AddEntity

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3048
Printed Date: 25-Mar-2025 at 9:38am


Topic: ArgumentOutOfRange AddEntity
Posted By: smi-mark
Subject: ArgumentOutOfRange AddEntity
Date Posted: 20-Oct-2011 at 9:43pm
I have no idea why this is happening

I have the following code, and it only seems to happen with this entity type:

        public PromotionLine AddProduct(Product product)
        {
            var promotionLine = new PromotionLine
                                    {
                                        PromotionId = PromotionId,
                                        PromotionLinkType = (byte)PromotionLinkType.Product,
                                        LinkId = product.ProductId
                                    };
            EntityManager.AddEntity(promotionLine);
            return promotionLine;
        }


Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at IdeaBlade.EntityModel.EntityKey.ConvertValues()
at IdeaBlade.EntityModel.EntityGroup.FindEntityWrapper(EntityKey entityKey, Boolean includeDeleted)
at IdeaBlade.EntityModel.EntityManager.FindEntityWrapper(EntityKey entityKey, Boolean includeDeleted)
at IdeaBlade.EntityModel.ScalarEntityReference`1.FindToEntity()
at IdeaBlade.EntityModel.ScalarEntityReference`1.FixupReferences()
at IdeaBlade.EntityModel.EntityAspect.<FixupReferences>b__19(EntityReferenceBase eref)
at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
at IdeaBlade.EntityModel.EntityAspect.FixupReferences()
at IdeaBlade.EntityModel.EntityAspect.TrackChanged(EntityChangedEventArgs e)
at IdeaBlade.EntityModel.EntityGroup.OnEntityChanged(EntityChangedEventArgs e)
at IdeaBlade.EntityModel.EntityGroup.AddAttachedEntity(EntityAspect wrapper, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.AttachEntityAspect(EntityAspect aspect, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.AttachEntity(Object entity, EntityState entityState)
at IdeaBlade.EntityModel.EntityManager.AddEntity(Object entity)

Even just doing this errors:

            var promotionLine = new PromotionLine();             EntityManager.AddEntity(promotionLine);


This is the ctor:

        internal PromotionLine()         {             PromotionLineId = Guid.NewGuid();         }

Any clues?




Replies:
Posted By: smi-mark
Date Posted: 20-Oct-2011 at 10:18pm
Upgraded to 6.1.3.1 no difference.


Posted By: smi-mark
Date Posted: 21-Oct-2011 at 8:47am
Something is altering the Entity after AddEntity and before it hits ConvertValues, or it's not finding the key.

calling this works fine:

    var method = typeof(EntityKey).GetMethod("ConvertValues"BindingFlags.NonPublic | BindingFlags.Instance);
            method.Invoke(key, null);

The problem seems to start from  IdeaBlade.EntityModel.EntityManager.FindEntityWrapper(EntityKey entityKey, Boolean includeDeleted)



Posted By: smi-mark
Date Posted: 21-Oct-2011 at 7:48pm
Any clues? It's got something to do with the relationship to the Promotion table.  As soon as I delete the association it works fine.

Promotion is an abstract table, there are two tables PercentageOffPromotion and SpecialPricePromotion that inherit from it.

This was working fine for ages. I have no idea what is causing the problem.


Posted By: smi-mark
Date Posted: 22-Oct-2011 at 5:52pm
I think I found the problem. I completely recreated the entities, but then I noticed there were some old entities that still inherited from Promotion. They didn't exist in the model but the partial files still existed. I'm not sure why it was erroring though. Very strange.


Posted By: DenisK
Date Posted: 24-Oct-2011 at 11:26am
Hi smi-mark;

We can investigate this further if you can send us your edmx, a sql script to create the involved tables and any other info that you think might help us reproduce the issue here. You can use the customer's support form to attach your files.

http://www.ideablade.com/technical-support/CustomerSupportRequestForm.aspx - http://www.ideablade.com/technical-support/CustomerSupportRequestForm.aspx



Print Page | Close Window