1

Using Azure.Data.Tables 12.3.0 and trying to save the following sample model I get the error:

System.NotSupportedException: Not supported type System.Collections.Generic.Dictionary [System.Guid,System.Guid] at Azure.Core.Utf8JsonWriterExtensions.WriteObjectValue(Utf8JsonWriter writer, Object value) at Azure.Data.Tables.TableRestClient.CreateInsertEntityRequest(String table, Nullable timeout, Nullable responsePreference, IDictionary tableEntityProperties, QueryOptions queryOptions)

PersistedPerson.cs

class PersistedPerson
{
  string Name { get; init; }
  Dictionary<Guid, Guid> SomeDictionary { get; init; } = new();
}

To save the entity I'm creating it and passing it into my repository where I create the TableClient and save the entity as follows:

var tableClient = new TableClient(tableStorageConfiguration.ConnectionString, tableName);
await tableClient.AddEntityAsync(persistedModel, cancellationToken);

I can save this object without issue using Microsoft.Azure.Cosmos along with Cosmos DB (emulator and the service). I have tried using the Azure Storage Emulator 5.1.0 and Azure Table Storage (online). It also doesn't seem to matter what data types are used in the dictionary; I get the same error.

Any suggestions? I can't find a lot of information out there about what serialization support there is for this library. It looks like it's serializing using a JSON writer of some kind and I've verified System.Text.Json is supported.

[Update] Swapping out library and underlying implementation did indeed fix this issue. Works fine in CosmosDb (SQL) but not CosmosDb Tables.

Jason Shave
  • 2,462
  • 2
  • 29
  • 47
  • _Azure Storage Emulator_ is useless at this point because it differs so much from production services. Is there a reason you can't use a storage account in real-life Azure for testing? – Dai Nov 26 '21 at 02:46
  • That said - are you actually storing data in Azure Table Storage (ATS), or in Azure CosmosDB? ATS is far, far, far more restricted and limited in the kinds of data models you can express (e.g. you cannot have a `Dictionary` or collection member in ATS table entity types), though a workaround is to use `DynamicTableEntity` and map child dictionary keys to dynamic members of the parent entity type... – Dai Nov 26 '21 at 02:48
  • Switched to the Azure Table Storage account online and have the same issue. I'll swap out the back end for Cosmos and carry on. Was hoping to save some cost and had great luck with Table Storage in the past. – Jason Shave Nov 26 '21 at 03:27
  • Right - that's fine - you can still use ATS, you just need to handle the conversion from your `PersistedPerson` mini-object-graph to a _flat_ `DynamicTableEntity` ATS entity object by yourself (and back-again). – Dai Nov 26 '21 at 03:28
  • Ya, the previous version of the library `Microsoft.Azure.Cosmos.Table` I was able to use `DynamicTableEntity` just fine but this new library doesn't have such an object. It takes care of flattening for you as your persisted entities need to inherit `ITableEntity` now or you have to persist a `TableEntity` directly. – Jason Shave Nov 26 '21 at 03:31

0 Answers0