I am using httpClient to an API endpoint. There are a couple of possible JSON results I could get back depending on if the call if successful or not.
So I want to use a dynamic or ExpandoObject to DeserializeObject the results to.
However, I can't seem to be able to actual get anything from the object after Deserializing. I keep getting `
error CS1061: 'object' does not contain a definition for 'success' and no accessible extension method 'success' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)'
Here is a simplified example:
dynamic stuff = JsonConvert.DeserializeObject<ExpandoObject>("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");
When I try to access name like this stuff.name I get the following error:
error CS1061: 'object' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) ? stuff["name"] error CS0021: Cannot apply indexing with [] to an expression of type 'object'
And yet the data is in there somewhere:
If I Deserialize like this I get the exact same result:
dynamic stuff = JsonConvert.DeserializeObject("{ 'Name': 'Jon Smith', 'Address': { 'City': 'New York', 'State': 'NY' }, 'Age': 42 }");
It was inferred in another post that it may have something to do with this being in an async function, but no real solution. I am running .Net core 3.1 from within an Azure function.
So how do I refer to the object to get a value out?

Namenotname-- capitalization matters. AnywayExpandoObjectimplementsIDictionary<String,Object>so you can loop though or search for members that way, see How to dynamically get a property by name from a C# ExpandoObject?.var byName = (IDictionary<string, object>)stuff; string val = (string)byName["Name"];and for nested objects:var address = (IDictionary<string, object>)stuff.Address; string city = (string)address["City"];Pretty clumsy, but works.stuff.Nameworks also, see dotnetfiddle.net/wA9SXA. Not sure where your problem is.