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
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; }
}
}
The text was updated successfully, but these errors were encountered:
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");
}
The text was updated successfully, but these errors were encountered: