You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected result Deserializing by constructor #233
I have been running tests with MessagePack CLI, and have experienced unexpected results when deserializing immutable classes via a single constructor.
It works as expected with writable properties, but via the constructor, two of the parameters are left null, and rather than setting the dictionary back to the expected property, it is assigned to a string property. This can be viewed while debugging, but crashes as soon as you try to programmatically access the property (AccessVioloationException).
Please see the code below for a better explanation. It looked from a few earlier issues on here that constructor deserialization is possible. Am I correct in this assumption?
Thanks
Chris
using System.Collections.Generic;
using MsgPack.Serialization;
namespace MessagePackCSharp
{
class Program
{
static void Main(string[] args)
{
var endpoints = new EndpointList(
"Test String One",
new Dictionary<string, string[]>
{
{ "ConfigService", new [] { "ur1", "ur2" } },
{ "TestService", new [] { "ur1", "ur2" } }
},
"Test String Two");
var ser = SerializationContext.Default.GetSerializer(typeof(EndpointList));
var bytes = ser.PackSingleObject(endpoints);
var endpointsDeser = (EndpointList) ser.UnpackSingleObject(bytes);
// endpointsDeser has very strange values, with one of the string properties being assigned
// the dictionary
}
}
public class EndpointList
{
public EndpointList(string stringOne, Dictionary<string, string[]> endpoints, string stringTwo)
{
StringOne = stringOne;
Endpoints = endpoints;
StringTwo = stringTwo;
}
public string StringOne { get; }
public Dictionary<string, string[]> Endpoints { get; }
public string StringTwo { get; }
}
Activity
yfakariya commentedon Apr 24, 2017
Sorry, it is bug of constructor deserialization.
You can avoid this to align orders of constructor parameters and properties as one of following.
[MessagePackMember]with constructor parameter order.Fix wrong code generation for constructor based deserialization. #233
Fix wrong code generation for constructor based deserialization. #233
Fix wrong code generation for constructor based deserialization. #233
Merge pull request #236 from msgpack/fix/#233