Trying to handle Azure storage table operations using .net core. I have successfully added a new storage table and inserted the new row with unique rowKey (I tested the insertion with re-insertion which gave me conflict which means it already has a key). When I am trying to retrieve the same key with rowKey =1 which I have inserted then getting an error.
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(StorageConnectionString);
//create storage table
CreateTable(cloudStorageAccount).GetAwaiter().GetResult();
InsertEntity(cloudStorageAccount).GetAwaiter().GetResult();
RetrieveEntity(cloudStorageAccount, "blog", "1").GetAwaiter().GetResult();
public static async Task RetrieveEntity(CloudStorageAccount cloudStorageAccount,
string partitionKey, string rowKey)
{
var cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
var cloudTableReference = cloudTableClient.GetTableReference("MyAzureTableStorage");
TableOperation retrieve = TableOperation.Retrieve<BlogEntity>(partitionKey, rowKey);
var result = await cloudTableReference.ExecuteAsync(retrieve);
if(result.Result == null)
{
Console.WriteLine("Not able to find the results");
}
else
{
Console.WriteLine($"Blog found for author: {((BlogEntity)result.Result).Author}");
}
}
Getting an error:
Microsoft.WindowsAzure.Storage.StorageException
HResult=0x80131500
Message=No parameterless constructor defined for this object.
Source=Microsoft.WindowsAzure.Storage
StackTrace:
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor. <ExecuteAsyncInternal>d__4`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at AzureTable.Program.<RetrieveEntity>d__3.MoveNext() in D:\Manish \Practice\AzureIt\AzureTable\Program.cs:line 46
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at AzureTable.Program.Main(String[] args) in D:\Manish\Practice\AzureIt\AzureTable\Program.cs:line 21
Inner Exception 1:
MissingMethodException: No parameterless constructor defined for this object.
BlogEntity class :
public class BlogEntity : TableEntity
{
public BlogEntity(int ID, string author, string title, string description)
{
this.UniqueID = ID;
this.Author = author;
this.Title = title;
this.Description = description;
this.PartitionKey = "blog";
this.RowKey = ID.ToString();
}
public int UniqueID { get; set; }
public string Author { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}