Hello i am having a class that is defined in a .Net Standard
assembly.
Now i have a reference to that assembly from my .Net Core
project.
When i try to deserialize the class in my .Net Core
my class fields are default.
By default i mean value types get all inner values default and class fields are null.
In my example if Val
is an int
it would have its value 0
after deserialization whereas would it have been a class
it would be null.
.NET Standard class
public class Matrix
{
public int Val { get; set; }
public Matrix(int set) //value is default
{
this.Val = set;
}
}
.NET Core
static void Main(string[] args)
{
Matrix matr = new Matrix(3);
var str=JsonConvert.SerializeObject(matr);
var bytes=Encoding.Utf8.GetBytes(str);
var str = Encoding.UTF8.GetString(bytes); //string looks ok !
var deser = JsonConvert.DeserializeObject<Matrix>(str);
}
Please note that my class uses a parameter in the constructor.Could this be the problem ? If my parameter constructor is indeed the problem ...how do you manage to serialize an object that needs to perform some logic in its constructor via his parameters ?