WCF EF 4.1 persistence excludes the item. Item cannot be added to fixed size Array type

I searched google and ran out of the honest part of my time trying to figure out what's going on with my WCF and client.

I keep getting the following error:

"Unable to set field/property Ingredients on entity type Datalayer.UnitOfMeasure. See InnerException for details."
...
inner exception is 
"An item cannot be added to a fixed size Array of type 'Datalayer.Ingredient[]'."


Stack Trace - 
    at System.Data.Objects.Internal.PocoPropertyAccessorStrategy.<AddToCollection>b__0[T](Object collectionArg, Object item)
       at System.Data.Objects.Internal.PocoPropertyAccessorStrategy.CollectionAdd(RelatedEnd relatedEnd, Object value)

      

How I set up my solutions I have a WCF web service that references my DataLayer class library, I have a Windows application (test application) that references WCF services as well as a DataLayer project.

If I do not reference the DataLayer in my test application, these problems do not occur, but I lose the array ICollection<Ingredient>

to a simple one Ingredient[]

. Now, as you can see, this becomes the reason for the coding to initialize the array every time.

Somebody knows? thank you in advance.

+3


source to share


3 answers


When you add a WCF service reference in a test using Add Service Reference, it is possible to configure the default collection type for the generated proxy on the client. I consider an array by default, you can change it to a generic list.



If you are using svcutil this does the same thing too.

+2


source


I ran into this exact error, but the accepted answer was not exactly the solution I needed. It turns out the client sent List<Order>

up to my WCF service, but since the property Customer.Orders

was defined as ICollection<Order>

, the WCF deserializer deserializer just deserialized it in its simplest form, which could be an array of type Order, i.e. Order[]

...



The only solution I could think of was to change the property in question to my POCO objects from ICollection<Order>

before HashSet<Order>

. See Stop WCF Deserializing Empty ICollection on Zero Capacity Array for more details.

+8


source


Weird. I had the same error and was doing the right thing by calling "ToArray ()". Changed it to "ToList ()" and it started working fine.

0


source







All Articles