polenter / SharpSerializer

SharpSerializer can serialize types like: multidimensional array, nested array, array-of-arrays, polymorphic object (where value is inherited from the property type), generic type, generic listing (i.e. dictionary, collection) and many more, with a single line of code
https://www.sharpserializer.net
Other
114 stars 28 forks source link

When deserialize SharpSerializer throw "Constructor on type not found." #33

Closed Mutuduxf closed 9 months ago

Mutuduxf commented 11 months ago

Hi, I'm new to SharpSerializer. When I try to write a demo, the serialize function is OK, but when I deserialize the serialize result, SharpSerializer throws an inmost ex "Constructor on type not found.". The code is like this:

public class MyClass
{
    public int Id { get; set; }
    public string? Name { get; set; }
}

public void Test()
{
        var myObject = new MyClass { Id = 1, Name = "Example" };

        var serializer = new Polenter.Serialization.SharpSerializer();
        var ms = new MemoryStream();
        serializer.Serialize(myObject,ms);
        ms.Seek(0, SeekOrigin.Begin);

        // this line throws the ex
       var deserializedObject = serializer.Deserialize (ms) as MyClass;
}