I have problem with dynamic object.
I have method which return something like:
public async Task<dynamic> GetItemBasicInformation(string itemId)
{
var apiUrl = $"{WebConfigurationManager.AppSettings["apiAdress"]}{itemId}";
var result = await _httpClientHelper.GetRequest(apiUrl);
return new
{
name = result["name"].Value<string>(),
itemId = result["itemId"].Value<string>(),
attributes = result["attributes"].Values<JToken>()
};
}
Then I want to read properties from dynamic object in another class:
[ActionName("test")]
public async Task<IHttpActionResult> GetTest()
{
dynamic item = await _testItemHelper.GetItemBasicInformation("TI-1658001");
var name = item.name;
return Ok();
}
Also this method is in another assembly than GetItemBasicInformation() method.
Unfortunately I get ''object' does not contain a definition for 'name'' exception, but debugging show me that item contains all properties with value.
Why am I getting this error and how can I solve this problem?