Sabby62
Sabby62

Reputation: 1717

JSON to dynamic - 'Newtonsoft.Json.Linq.JObject' does not contain a definition

I am using MVC WebAPI and passing in JSON object to a method that has parameter defined as dynamic. When using the method I am accessing the property of the dynamic object. It throws me this error - 'Newtonsoft.Json.Linq.JObject' does not contain a definition'

private dynamic Method1([FromBody]dynamic obj)
{
  if (obj.Name.Value == "Hello")
  {
   //Code
  }
}

JSON has right Key-Value pair.

This code works fine on other machine but throws error on one. Just wondering if there is something wrong with my installation or I am missing something ?

Upvotes: 3

Views: 5542

Answers (3)

Aravindhan R
Aravindhan R

Reputation: 269

The creator of JSON.Net himself addressed it here

Assuring that it's something minor and the exception is by design.

By the way if you wish to disable these warnings just because they make you uncomfortable.

In Visual Studio click on Tools - > Options and then select Debugging and Check the box that says Enable Just My Code.

More Info Stackoverflow

Upvotes: 0

v.shashenko
v.shashenko

Reputation: 736

I had a similar problem with an app that used Json.NET as a private assembly. The issue ocurred only on a 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.

Upvotes: 5

Sabby62
Sabby62

Reputation: 1717

Cleared the dll from GAC and everything works fine now!

Upvotes: 1

Related Questions