0

I am using some ExpandoObject dynamics in a MVC application of mine and I am running into the above error. It only is seeming to happen with one or two properties but it is consistent. I will get the run-time error stating that no such property exists and then, when looking deeper and expanding the dynamic view of the the object in the VS debugger the property exists on the object and has a value.

Has anyone experienced this before and if so do you have any insight?

I have tried casting the object to see if that would work but I got the same error. The code that I used to cast it follows as an example of some of the things I have already tried mostly just to see if I could get at the property at all.

var cur = new ExpandoObject() as IDictionary<string, object>;
cur = inputDynamic;
string property = (string)cur["propertyName"];
tereško
  • 58,060
  • 25
  • 98
  • 150
Bozarth
  • 166
  • 1
  • 8
  • What is inputDynamic? You are reassigning cur so that cur is no longer the new ExpandoObject you instantiated. Maybe you meant to set cur["propertyName"] = inputDynamic? Also, you don't have to use the dictionary syntax, you can just reference inputDynamic.PropertyName. (I would pascal-case rather than camel-case property names on classes.) – Geoff Cox Aug 13 '13 at 17:43
  • inputDynamic is the input to the function. I am reassigning cur to "type cast" the incoming dynamic. It is a generic dynamic and you can "type cast" it by instantiating an instance of an Expando that inherits what you need it to (in my case dictionary) to in essence type cast the dynamic as a dictionary. I am aware that I can use dot notation. I mentioned previously in my post that I was trying the posted code as a secondary option to see if it showed up in the dictionary. The issue was that the property was set sort of like this and someone had accidentally slipped a space in after the name. – Bozarth Aug 15 '13 at 15:13

0 Answers0