Skip to content

Using InsertOrReplace/InsertOrMerge with the Storage Client!

Trying out the new Replace or Insert option(Upsert) in the Storage Client and can’t get rid of the following error message

“"\r\n<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n  InvalidHeaderValue\r\n  <message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.\r\n"”

The main issue is that the new API is available only in the "2011-08-18" version which the storage dll does not hit . The reason the below code is necessary is because the released library sends an older storage version “2009-09-19” that does not support these newly released features

So we need to specifically set the headers in the data-context request. Also remember that this does not work with the local development storage ( at least as of now), so remember to use these headers ( and these operations) only with the Cloud storage account.

dataContext.SendingRequest +=
(sender, args) => (args.Request).Headers["x-ms-version"] = "2011-08-18";

dataContext.AttachTo(, );
dataContext.UpdateObject();
dataContext.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);

This gives you Insert Or Replace option with Storage Client Lib!!

If you leave the SaveChangeOptions.ReplaceOnUpdate option then you get Insert or Merge!

Until Next time!

Team Cennest!

Leave a Reply

Your email address will not be published. Required fields are marked *