dotnet / dotnet/orleans

Serializer (for PersistentState) does not use AliasAttribute on State type

Open
#8,396 3 comments 2 reactions 1 assignee Claimed by @ReubenBond View on GitHub
question
Dominant language
C#
Stars
10.9k
Forks
2.1k
Avg merge
14h 42m
Merged PRs (30d)
354

Description

(Orleans version: 7.1.1)
Maybe my understanding of this topic is incorrect, but i believe this behaviour is not good:
I want to give my state types an alias (as suggested in the docs) so that those types can be refactored/renamed without breaking existing persisted grain states.

Example:
```csharp
public class TestGrain : Grain, ITestGrain
{
private IPersistentState GrainState { get; }

public TestGrain([PersistentState("TestGrainState", "defaultStore")] IPersistentState grainState)
{
GrainState = grainState;
}

public async Task Init()
{
this.GrainState.State = new TestState
{
SomeField = "something",
SomeOtherField = "something else"
};

await this.GrainState.WriteStateAsync();
}
}
```

```csharp
[Alias("myalias")]
[GenerateSerializer]
public class TestState
{
[Id(0)]
public string SomeField { get; set; }

[Id(1)]
public string SomeOtherField { get; set; }
}
```
however, the full type names are serialized to storage, and (de)serialization breaks if those are renamed:

```json
{"$id":"1","$type":"WebApplication1.TestState, WebApplication1","SomeField":"something","SomeOtherField":"something else"}
```

Is this a bug or is there a better way to make serialization refactoring-safe?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.