Trying to retrieve some data from Azure Table Storage using Azure.Data.Tables
The below code, when using TableEntity works fine but when I use my own class derived from ITableEntity I get an exception at the foreach when it’s trying to get the data.
Pageable<TaskInfo> tasks = tableClient.Query<TaskInfo>(t => t.PartitionKey == "20210325");
Pageable<TableEntity> tasks2 = tableClient.Query<TableEntity>(filter: $"PartitionKey eq '20210325'");
foreach (var task2 in tasks2)
{
Console.WriteLine($"{task2.GetString("TaskDescription")}");
}
Console.WriteLine($"The query returned {tasks2.Count()} entities.");
foreach (var task in tasks)
{
Console.WriteLine(task.TaskDescription);
}
Console.WriteLine($"The query returned {tasks2.Count()} entities.");
public class TaskInfo : ITableEntity
{
public string? PartitionKey { get; set; } = "";
public string? RowKey { get; set; } = "";
public DateTimeOffset? Timestamp { get; set; }
public ETag ETag { get; set; }
...
}
System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null. (Parameter 's')
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Int64.Parse(String s, IFormatProvider provider)
at Azure.Data.Tables.TablesTypeBinder.TryGet[T](BoundMemberInfo memberInfo, IDictionary`2 source, T& value)
at Azure.Core.TypeBinder`1.BoundMemberInfo`1.Deserialize(TExchange source, Object o, TypeBinder`1 binderImplementation)
at Azure.Core.TypeBinder`1.BoundTypeInfo.Deserialize[T](TExchange source)
at Azure.Data.Tables.DictionaryTableExtensions.ToTableEntity[T](IDictionary`2 entity, BoundTypeInfo typeInfo)
at Azure.Data.Tables.DictionaryTableExtensions.ToTableEntityList[T](IReadOnlyList`1 entityList)
at Azure.Data.Tables.TableClient.<>c__DisplayClass56_0`1.<Query>b__0(Nullable`1 pageSizeHint)
at Azure.Core.PageableHelpers.<>c__DisplayClass12_0`1.<CreateEnumerable>b__0(String _, Nullable`1 pageSizeHint)
at Azure.Core.PageableHelpers.FuncPageable`1.<AsPages>d__4.MoveNext()
at Azure.Pageable`1.<GetEnumerator>d__8.MoveNext()
at AnalyzeImportProcesses.Program.AnalyzeRetailPriceImportProcess() in C:UserscwardsourcereposAnalyzeImportProcessesAnalyzeImportProcessesProgram.cs:line 44
at AnalyzeImportProcesses.Program.Main(String[] args) in C:UserscwardsourcereposAnalyzeImportProcessesAnalyzeImportProcessesProgram.cs:line 23
4
Turns out one of my properties on my TaskInfo class called TaskID should of been TaskId. It would be nice if the error message was clearer on this or if there is a way to get around something like this.
The method I used to figure it out was comment out all of the properties except for what ITableEntity required and one by one uncommented them until I found the one that was causing the error.