Comments (10)
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.
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.
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.
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.
@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.
And if we substitute new()
for []
, everything works as expected.
from orleans.
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.
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.
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.
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)
- Client receive response with delay/timeout when there are high concurrent request to a grain HOT 4
- Undisposed Cancellation Tokens Sources
- Grain State changes when silo restarts HOT 4
- After update to 8.2 version my streams stopped working HOT 5
- PooledBuffer does not recycle memory pool objects
- Issue with generated codec for referenced project record message type HOT 15
- Duplicate state created HOT 1
- Virtual methods as a way of eliminating the need for interfaces? HOT 1
- Inconsistent int grain key formatting
- The `name` parameter of `[PersistentState]` should be made optional
- Problems when using your own code generator before Orleans code generator runs HOT 3
- Disabling the population of the state when activating a grain during the invocation of a specific method HOT 1
- Does MessagePack also follow the DeepCopy strategy? HOT 1
- II don't understand why a CodecNotFoundException is thrown HOT 2
- how do i change in AdoNetClusteringSiloOptions, dbo schema
- Race condition in PersistentStreamPullingAgent can cause events to get dropped when using SimpleQueueCache HOT 5
- [BUG/Feature Request] Serialization: Converters that convert to base types
- Orleans Node Interleaved Upgrade Causes Placement Strategy Not to Update
- Stale Records in Dynamo DB
- PersistentState and IPersistentState require to reference Microsoft.Orleans.Runtime
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orleans.