locked
An item cannot be added to a fixed size Array exception RRS feed

  • Question

  • Hi all,

    When trying to add an entity that has a reference property to another entity via a wcf service, the following exception is being thrown:

    System.Data.EntityException was unhandled by user code
      Message=Unable to set field/property WorkflowInstances on entity type SAG.Taskflow.Common.Model.WorkflowType. See InnerException for details.
      Source=System.Data.Entity

    InnerException: System.InvalidOperationException
           Message=An item cannot be added to a fixed size Array of type 'SAG.Taskflow.Common.Model.WorkflowInstance[]'.
           Source=System.Data.Entity

    the WorkflowInstance is the type of the entity that is being added with a WorkflowType property. WorkflowType has a ICollection<WorkflowInstance> property.

    Note that adding the item the first time doesn't raise the problem, the  ICollection<WorkflowInstance> of the WorkflowType is being set correctly. But when adding the instance the second time, the exception is being thrown.

    Wednesday, May 2, 2012 12:12 PM

All replies

  • Could you please post some code here?

    Go go Doraemon!

    Friday, May 4, 2012 2:56 AM
  • public class WorkflowInstance

    { public int ID { get; set; } public string Name { get; set; } public virtual WorkflowType WorkflowType { get; set; } } public class WorkflowType { public int ID { get; set; } public string Name { get; set; } public virtual ICollection<WorkflowInstance> WorkflowInstances { get; set; } } // call from inside the workflow databaseService.AddWorkflowInstance(dataContract); // service contract implementation public void AddWorkflowInstance(WorkflowInstanceDataContract workflowInstanceDataContract) { dataAccess.AddWorkflowInstance(workflowInstanceDataContract.WorkflowInstance); } // data access layer public void AddWorkflowInstance(WorkflowInstance workflowInstance) { db.WorkflowInstances.Add(workflowInstance); db.SaveChanges(); }


    The WorkflowInstanceDataContract is the follows:

    [DataContract]
        public class WorkflowInstanceDataContract
        {
            private WorkflowInstance workflowInstance;
    
            public WorkflowInstanceDataContract()
            { }
    
            [DataMember]
            public WorkflowInstance WorkflowInstance
            {
                get { return this.workflowInstance; }
                set { this.workflowInstance = value; }
            }
        }

    When calling the service contract a second time, the exception is being thrown at db.WorkflowInstances.Add(workflowInstance);

    Friday, May 4, 2012 10:22 AM
  • change your WorkflowInstances property to a List instead of ICollection as below

    from: public virtual ICollection<WorkflowInstance> WorkflowInstances { get; set; }

    to: public virtual List<WorkflowInstance> WorkflowInstances { get; set; }

    this solved my issue on my EF5.0 generated classes!!!

    • Proposed as answer by jaisi001 Wednesday, October 30, 2013 7:35 AM
    Wednesday, October 30, 2013 7:34 AM