New Posts New Posts RSS Feed: ArgumentOutOfRange AddEntity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

ArgumentOutOfRange AddEntity

 Post Reply Post Reply
Author
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Topic: ArgumentOutOfRange AddEntity
    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?



Edited by smi-mark - 21-Oct-2011 at 8:15pm
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 20-Oct-2011 at 10:18pm
Upgraded to 6.1.3.1 no difference.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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)

Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down