Failed to deserialize change-set. Operation is not valid due to the current state of the object.

I’ve written a domain service that allows basic CRUD operations for a person’s “Contacts”.Â Lots and lots of unit tests run just fine against the server side code, and the Silverlight client can download all the contacts I put into the database using a SQL script and display them very nicely.

Unfortunately, I can’t create a new contact from the Silverlight side.Â In the submit operation’s completed event handler I get the error message:

1

2

3

4

5

6

{System.Windows.Ria.Data.EntityOperationException:

Failed to deserialize change-set.Operation isnot valid due to the current state of the object.

at System.Windows.Ria.Data.HttpDomainClient.GetRequestResult(HttpDomainClientAsyncResult httpAsyncResult)

at System.Windows.Ria.Data.HttpDomainClient.EndSubmitCore(IAsyncResult asyncResult)

at System.Windows.Ria.Data.DomainClient.EndSubmit(IAsyncResult asyncResult)

at System.Windows.Ria.Data.DomainContext.CompleteSubmitChanges(IAsyncResult asyncResult)}

However,Â in the submit operation completed event handler submitOp.EntitiesInError.Count()=0.Â Thus, it doesn’t seem to be my new contact instance object that’s the problem.

I’ve overriden all the methods in the domain service adding try/catch blocks (or at least a breakpoint) and just calling base.whatever()Â the only method that seems to be called is the Initialize(DomainServiceContext context) method, which completes normally.Â The insert method of the domain service is definitely not called:

1

2

3

4

5

6

7

8

9

10

[Insert]

publicvoidAddContact(ContactDto newContact){

Contract.Requires(GetCurrentUserId()!=null,"The request must be authenticated");

Contract.Requires(newContact!=null,"The contact to add must not be null");

Contract.Requires(newContact.Id==0,"All new contacts must have a zero ID");

Contract.Ensures(newContact.Id!=0,"The contact's ID should not be zero after adding it to the database");

So, in a separate solution I started from scratch and created a new SilverlightÂ .NET RIA Services project. I copied the definition of the DTO contact class into this new project.Â I can easily create new instances of the DTO contact class in the new project.Â Â Then I copied my simplified GUI in to the original project and it doesn’t work, I get the same error as above.Â Then I copied my simplified domain service to the original project and it STILL doesn’t work, I get the same error.

The contact DTO class was being automatically generated by my ORM tool, and was being annotated by that tool as follows:

1

2

3

4

[System.Runtime.Serialization.DataContract(Name="Contact")]

publicpartial classContactDto:BaseEntityDto{

....

}

When I had previously copied the DTO code to my simplified experimentation project I had not copied the attributes.Â The moment I copied the attributes it stopped working.Â Changing the name of the data contract to match the name of the class fixes the problem.