Comments (4)
When using non-default constructors for deserialization, you should apply [SerializationConstructor]
on the constructor. Does that resolve the issue?
from messagepack-csharp.
Thanks for the suggestion. Unfortunately no, applying [SerializationConstructor]
to the constructor does not change anything - I still get the "No set accessor" exception.
However, if I add an extra constructor that is never used by me or the serialization process, then it works:
[SerializationConstructor]
private Player()
{
// This will never be called
throw new NotImplementedException();
}
Still, it does not make much sense to me why such a constructor is needed - and indeed, it was not necessary in previous versions of the nuget.
It makes sense in the case of deserialization when it needs a constructor to construct the object, but not serialization.
from messagepack-csharp.
Thanks for trying it out. I agree this seems like a regression and I'll try to find time to investigate and correct it.
I agree deserialization's requirements aren't fundamentally the same as for serialization. But the dynamic object resolver creates a formatter to serialize and deserialize at the same time, and at the moment, it enforces requirements for both scenarios when the formatter is generated. That is something we could improve on in the future.
from messagepack-csharp.
I can repro the failure. But now that I'm looking at it more closely, I agree with it, modulo the missing support for non-deserializable objects that I mentioned before. For future reference, here's why:
- The only property that could be effectively serialized is your
Name
property. Scores
is ignored by an explicit attribute.TotalScore
is supposed to be serialized, but it doesn't store a value. It's computed from the ignored property. And it has no setter as a result. So the serialized form cannot be used to construct a deserialized object.
This is as @F2 said in the first place. I just misunderstood the nuance.
Anyway, if and when MessagePack's DynamicObjectResolver ever supports types that can only be serialized or deserialized (not both), then this is a good example of a type that should start working at that point. I imagine the way we could achieve that is for the resolver to record that an object can only go one direction, and emit a formatter that throws when going the other direction. Ideally, the exception thrown if used in the unsupported direction would match the exception that the resolver itself currently throws so that it can point the user in the right direction to fix the problem if they intended bidirectional serialization.
I suspect the fact that this "worked" in prior versions was probably due to a hole in detection of the unsupported scenario, and you got lucky. To upgrade MessagePack and keep working, you can either use the workarounds you already mentioned, or write a custom formatter for this type.
I'm going to close this issue as Won't Fix because we don't have plans to support uni-directional serialization in the DynamicObjectResolver
any time soon.
from messagepack-csharp.
Related Issues (20)
- Private fields on base class do not get serialized HOT 4
- MessagePack.Generator.2.5.140 - Union metatag causes msc.exe error: Index was outside the bounds of the array
- Add parameter list `ref` usage analyzer for low level reader/writer HOT 1
- Fail in application running on MessagepackCompiler.RunAsync on Windows (works on Linux & macOS) HOT 5
- messagepack is missing NuGet package README file
- MsgPack003 does not generate error in all cases HOT 5
- Update readme file for Analyzer HOT 3
- Add Support for external types via class libraries HOT 1
- MsgPack003 errors showing in Rider for type with custom formatter HOT 5
- Typeless serializer fails to serialize simple type, unless fields are prefixed with "_" HOT 2
- Explicit interface implementation
- Help request - using different (derived-)types for serialize/deserialize (IMessagePackFormatter<Tser, Tdes>)? HOT 2
- Discrepancy in Serialized Size with MessagePack for Complex Object Graphs HOT 1
- Serialize/deserialize of interface types failing with ContractlessStandardResolver HOT 1
- Make System.Runtime.CompilerServices.Unsafe a conditional based on TFM
- Source generated formatter support of sparse/patch objects via BitArray HOT 5
- A conflict issue using MessagePack.Unityshims HOT 2
- Securely Save and Load for my game? HOT 1
- Wrong type of formatter for record with string keys HOT 2
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 messagepack-csharp.