Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MethodAccessException when trying to deserialize class #1710

Open
Seadoo2017 opened this issue Nov 30, 2023 · 0 comments
Open

MethodAccessException when trying to deserialize class #1710

Seadoo2017 opened this issue Nov 30, 2023 · 0 comments
Labels

Comments

@Seadoo2017
Copy link

Bug description

When trying to deserialize a class which has ctor with parameter (in addition to empty ctor) and the parameter name matches any property name (casing doesn't matter), and the class has any property with private setter, deserialization will fail with System.MethodAccessException

Repro steps

var m = new MemoryStream();
MessagePackSerializer.Serialize<MyClass>(m, new MyClass());
m.Seek(0, SeekOrigin.Begin);
var x = MessagePackSerializer.Deserialize<MyClass>(m);

[DataContract]
public class MyClass
{
    public MyClass()
    { 
    }

    public MyClass(string foo)
        : this()
    {

    }

    [DataMember]
    public string Foo { get; set; }

    [DataMember]
    public string Bar { get; private set; }   
}

Expected behavior

Deserialization should work properly.
There is no relation between the ctor parameter name and the property, notice that changing the ctor parameter name:
public MyClass(string foo) => public MyClass(string foo1)
Will make the issue disappear and everything works

Actual behavior

Deserialization throws exception

  • Version used: 2.5.129
  • Runtime: .net 7.0

Additional context

This scenario works as expected up until version 2.2.113, it broke since version 2.3.75+

@AArnott AArnott added the bug label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants