'New version .NET 6 is not work without get set
My old project is using .NET Core 2.2 and I need to migrate it to .NET 6.
The previous developer added some classes something like this:
public class ClassName
{
public int code;
public string message;
}
And API controller
[HttpGet]
[Route("GetTotal")]
public List<ClassName> GetTotal(DateTime dtCur)
{
List<ClassName> l = new List<ClassName>();
ClassName n = new ClassName()
{
code = -99,
message = "invalid session"
};
l.Add(n);
return l;
}
It worked on .NET Core 2.2, but on .NET 6, it always returns an empty array from ajax or Postman.
To get it done in .NET 6, I must fix class like this:
public class ClassName
{
public int code { get; set; }
public string message { get; set; }
}
But the problem is all classes in old projects they did not add { get; set; } to any classes, this mean I must fix all them.
Is there any way to fix it quickly, or someone can explain why in .NET 6 return empty in this case?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
