string json = File.ReadAllText($"./assets/JSON/{mapName}.json");
Console.WriteLine(json);
var gridMapData = JsonConvert.DeserializeObject<GridMapData>(json);
Here im deserializing an object and for release mode it works normally. But when compiled natively (PublishAot) like below:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<Platforms>AnyCPU;x64;x86</Platforms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PublishAot>true</PublishAot> --> here
</PropertyGroup>
This error Newtonsoft.Json.JsonSerializationException: Unable to find a constructor.
start happening ( from the same json and same class type to desserialize it ). Also, i can see on the Console.WriteLine that the json string is correctly being showed.
Appreciate any help or feedback.
I tried to satisfy the error by changing the class.
public class GridMapData
{
public int width;
public int height;
public Dictionary<string, int> cells;
--> Things i tried
//public GridMapData(int Width, int Height, Dictionary<string, int> Cells)
//{
// this.width = Width;
// this.height = Height;
// this.cells = Cells;
//}
//public GridMapData() { }
//[JsonConstructor]
//public GridMapData() { }
}
1