find a location for property in a new city

Thursday, 25 August 2011

Azure Table Storage One of the request inputs is out of range

While trying to insert an entity into a Windows Azure Table Storage table I got the rather ambiguous "An error occurred while processing this request." error message from a System.Data.Services.Client.DataServiceRequestException. The inner exception help a message of "One of the request inputs is out of range."

The error message wasn't terribly helpful but I finally found what was causing the problem. It was because of my Row Key. The RowKey property that comes from the TableServiceEntity abstract class has specific requirements which I was unintentionally breaching.

My RowKey was calculated from another property of my Entity. In this particular instance this meant the string included a '/' symbol. This is not allowed by Table Storage for RowKeys.

Solution

When calculating the RowKey from the other property I am now removing special characters that the Azure Storage does not allow. This includes forward slash (/) character, backslash (\) character, number sign (#) character, question mark (?) character.

Old code:
private string productName;
public string ProductName
{
   get { return productName; }
   //setting the RowKey and productName to the same value in one go
   set { RowKey = productName = value; }
}
New code:
private string productName;
public string ProductName
{
   get { return productName; }
   set { RowKey = Regex.Replace(productName = value, @"[\ /?#]", ""); }
}
I actually already knew about this from when I read Apress's Windows Azure Platform but the confusing error message threw me off on a tangent and hoped it hadn't done the same to anyone else.

Follow britishdev on Twitter

6 comments:

  1. BTW this will happen with PartationKeys too.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. how to retrieve all the table content without know Table fields name

    ReplyDelete