Wednesday 21 March 2012

Azure Table Storage - System.MissingMethodException: No parameterless constructor defined for this object. at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()

While working with Azure table storage, I got the following error message


System.MissingMethodException: No parameterless constructor defined for this object. at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
....


In order to resolve it, simply define parameterless constructor in the table entity class derived from class TableServiceEntity

e.g.



public class Customer: TableServiceEntity
    {
        public Customer(){} //This is a must to avoid MissingMethodException thrown :)

        //FirstName & LastName identifies row in the table uniquely
        public Customer(string fname, string lname)
        {
            this.PartitionKey = lname;
            this.RowKey = fname;
        }
        public int Age { get; set; }
    }

Cheers,
Milan Gurung