I have a project of .Net Standart class library which distributed as a nuget package. When I use this package for Asp.Net Core project, I get an internal exception (related to Newtonsoft Json) while using the same package and same code in a .Net Winform application works just fine. The .Net standart code of method that throws the exception is:
var jsonString = File.ReadAllText(jsonFilePath);
dynamic jResult = JsonConvert.DeserializeObject(jsonString);
foreach (dynamic feature in jResult.features)
{
...
}
The exception is: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'features'
Of course The json file I read has its 'features' property and is the same Json file for both projects. This code is tested with Unit test with the same Json file.
Unfortunately I haven't found the cause for this weird behavior of the fact that the same method in .Net Standard that pass unit tests and works good in .Net Framework, threw exception on .Net Core 😐 So I changed the code to use concrete classes instead of dynamic and now it runs good in all frameworks 🤷♂️