Newtonsoft JSON - Dynamic Objects

后端 未结 7 1871
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 09:52

I am using the Newtonsoft JSON library to perform dynamic deserialisation on incoming raw JSON and have found something that I just can\'t explain.

The starting poin

相关标签:
7条回答
  • 2020-12-08 09:59

    This is definitely some referencing issue, I just had the same problem, turned out the issue was that I had added the packages folder to the project so that I could check it in in VSS (sorry, mandatory), as soon as I removed the packages folder from visual studio, it started working fine

    0 讨论(0)
  • 2020-12-08 10:02

    I had the same problem.

    Json.NET 6.0.4 cause this issue.You should change it to Json.Net 6.0.5. None of the project should reference to Json.NET 6.0.4 .

    Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for solution... and check, if any of the projects use Json.NET 6.0.4, fix them.

    0 讨论(0)
  • 2020-12-08 10:09

    I had the same problem with an app using Json.NET. The issue recurred only on one specific machine and it turned out that the machine had another version of Json.NET installed in GAC. After removing it from GAC the app started to work correctly.

    0 讨论(0)
  • 2020-12-08 10:15

    I had this issue going on for a while, turns out, the DLL used was compiled for .NET 3.5 which did not support dynamic.... Make sure your DLL is compiled for .NET 4.5 and above

    0 讨论(0)
  • 2020-12-08 10:18

    You can try this:

    dynamic task = JObject.Parse(rawJson);
    

    Documentation: Querying JSON with dynamic

    0 讨论(0)
  • 2020-12-08 10:18

    In my case it turned out I was catching first chance exceptions, so although this exception was being thrown it was not, in fact, preventing my code from executing.

    It would still be nice to know why this happens for some content deserialized by Json.NET, but not all content. For example, I have a dynamic object i serialize with json.net in a unit test, then deserialize the serialized content. The serialized content looks identical to content which, at run time, causes runtime binder exceptions to be thrown.

    0 讨论(0)
提交回复
热议问题