GithubHelp home page GithubHelp logo

Comments (10)

ReubenBond avatar ReubenBond commented on September 22, 2024 4

Good find, thank you for reporting. It might be time for us to add serializers for unknown collection types. eg, if a type implements IEnumerable<T> but otherwise has no known serializer, enumerate it to a list and serialize it as such. It would solve the issue with returning LINQ queries, too.

from orleans.

cbgrasshopper avatar cbgrasshopper commented on September 22, 2024 2

We encountered a related issue with code like this:

private readonly List<Problem> _problems = [];

public List<Problem> Problems
{
  get
  {
    return _problems;
  }
  set
  {
    _problems.AddRange(value);
  }
}

public Problem Problem
{
  set => _problems.Add(value);
}

When the setter for Problems is called, _problems is null, so AddRange fails. The issue does not occur if we change the private field declaration to this (the remaining code is unchanged):

private readonly List<Problem> _problems = new();

from orleans.

icanhasjonas avatar icanhasjonas commented on September 22, 2024

Adding the expected error here just in case :-)

Orleans.Serialization.CodecNotFoundException: Could not find a codec for type <>z__ReadOnlyArray`1[System.String].

from orleans.

ReubenBond avatar ReubenBond commented on September 22, 2024

That is surprising behavior, @cbgrasshopper. I don't see any serialization attributes in that code, but I assume this error occurs post-deserialization?

from orleans.

cbgrasshopper avatar cbgrasshopper commented on September 22, 2024

@ReubenBond Yes, this is post-deserialization, and yes, this is surprising behavior 🤣 . I didn't include the serialization attributes in my snippet, but they are there as follows:

[GenerateSerializer]
[Alias("CommandOutcome")]
public record CommandOutcome
{
    private readonly List<Problem> _problems = [];

...

    [Id(0)]
    public List<Problem> Problems
    {
        get => _problems;
        set => _problems.AddRange(value);
    }

from orleans.

cbgrasshopper avatar cbgrasshopper commented on September 22, 2024

And if we substitute new() for [], everything works as expected.

from orleans.

cbgrasshopper avatar cbgrasshopper commented on September 22, 2024

Just discovered that we can also resolve it as follows:

[GenerateSerializer]
[Alias("CommandOutcome")]
public record CommandOutcome
{
    [Id(1)]
    private readonly List<Problem> _problems = [];

...

    [Id(0)]
    public List<Problem> Problems
    {
        get => _problems;
        set => _problems.AddRange(value);
    }

In this case, the collection expression works. Very interesting...

from orleans.

ReubenBond avatar ReubenBond commented on September 22, 2024

Oh, make sure you only give the field an [Id(...)], and not the property. That is important.
I'm still a little surprised this didn't work, since it looks like your type has a default constructor.

from orleans.

cbgrasshopper avatar cbgrasshopper commented on September 22, 2024

It does have a default constructor.

Oh, make sure you only give the field an [Id(...)], and not the property. That is important.

This seems like a worthwhile addition to the Serialization in Orleans documentation.

from orleans.

icanhasjonas avatar icanhasjonas commented on September 22, 2024

This is related - but also pretty much all Frozen collections also are failing on copy/serialization

public Task<IReadOnlySet<string>> ThisWillBreakSerialization() {
  return new HashSet<string> { "Hello World" }.ToFrozenSet();
}

from orleans.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.