dotnet / dotnet/orleans

Serializing polymorphic records with constructor parameters

Open
#9,026 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
10.9k
Forks
2.1k
Avg merge
13h 56m
Merged PRs (30d)
351

Description

Is serializing polymorphic records with constructor parameters supposed to work?

I mean something like this:

[GenerateSerializer]
public abstract record BaseRecord
{
  public abstract int test();
}

[GenerateSerializer]
public record DerivedRecord(int Value) : BaseRecord
{
  public override int test() => Value;
}

And then:

public interface ITestGrain : IGrainWithGuidKey
{
  Task<int> test(BaseRecord param);
}

public class TestGrain : Grain, ITestGrain
{
  public async Task<int> test(BaseRecord param)
  {
    return param.test();
  }
}

In my tests Value always has default value (zero). So result of the call is always zero (if serialization is involved, so not in local calls).

If I make Value a property instead of a constructor parameter then it works, but it means I can't easily make it read only.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the [GenerateSerializer] records and the ITestGrain/TestGrain call shown in the issue, then reproduce the non-local call using DerivedRecord(int Value). Trace the serialization and deserialization path to determine why Value becomes zero; done means the constructor parameter survives serialization and the grain returns the original value.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.