Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Polymorphism does not work properly #55

@pipalmic

Description

@pipalmic

I am trying to use a combo of Orleans, Orleans transactions, CosmosDB and polymorphism in my application.

So far I came up to the conclusion that the only way to make polymorphism work is to pass CosmosClient with a custom CosmosSerializer (just copied native implementation with proper TypeHandling) into the storage provider during the initialization. All the other attempts failed as JsonSerializerSettings and TypeHandling values of CosmosDBStorageOptions are ignored during the WriteStateAsync.

However, this custom CosmosClient has one drawback (or maybe a feature). During ReadStateAsync, the value of the State field has already the correct type (in case of Orleans transactions, the state is of TransactionalStateRecord type) when returned from CosmosClient whereas, without the custom implementation, the type of the State is JsonObject. This fact is causing an error on this line as .ToString() returns just a type name on TransactionalStateRecord, not a valid JSON.

grainState.State = JsonConvert.DeserializeObject(doc.Resource.State.ToString(), grainState.State.GetType(), this._options.JsonSerializerSettings);

Fixing is possible by checking if the type is JsonObject (do the current logic) or something else (set the state directly without deserialization) which I can do. However, I don't think this is the most beautiful solution in the world, haven't you already investigated a similar issue? Could be there some other pitfalls?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions