Azure Mobile Services gives System.AggregateException for ‘id’

icon_cloud_azure

During my work with Microsoft Azure’s Mobile Services I got a weird exception about the Id of the object that I wanted to update using the statement
[crayon-66065bdbee81c200039956/] The error that I kept receiving was:

System.AggregateException:  —> System.AggregateException:  —> Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: Error: When specified in the body, ‘id’ must match the id specified in the url.

So here’s what helped me fix this nasty exception:

No need to say that I checked the object’s Id property value and that it matched the Id stored in the (Azure SQL) table record that I tried to update.
I searched the web for an explanation and found that this error is given if the object’s Id property isn’t of type int (!)

Changing the Id value of the object class to int made the difference. Seems like the mobile webservices functions cannot find the object that you want to update unless the Id can be matched against the Id value in the record – which on its turn is stored as an int value.

This was weird since uploading a new record with an Id as a string works fine.

Better make a habit of always defining the Id property of type int and you’ll do just fine.