EDIT: restarting visual studio fixed this problem without changing the code.
I have a ConfigSection handler that uses dynamic types and an expando object. Testing is not responding. "object" does not contain a definition for "SportName" . I tried replicating in the console in which the ConfigSection handler got out of the equation, but the equivalent code seems to work fine. I'm at a dead end.
See below for test, ConfigurationSectionHandler and config xml
public class SportSection : IConfigurationSectionHandler { public object Create(object parent, object configContext, XmlNode section) { var doc = XDocument.Parse(section.OuterXml); var root = (XElement)doc.FirstNode; try { var sportList = root.Element("sportList").Elements("sport").Select(ToSport); dynamic config = new ExpandoObject(); config.SportList = sportList; return config; } catch (Exception ex) { throw new ConfigurationErrorsException("Invalid SportSection configuration", ex); } } private static dynamic ToSport(XElement sportElement) { try { var getAttrib = new Func<XElement, string, string>((x, atr) => x.Attribute(atr).Value); var getDictionary = new Func<IEnumerable<XElement>, IDictionary<string, string>>(elems => elems.ToDictionary(x => x.Attribute("name").Value, y => y.Attribute("value").Value)); return new { SportName = sportElement.Attribute("name").Value, EventProperties = getDictionary(sportElement.Element("eventProperties").Elements("property")), CompetitionProperties = getDictionary(sportElement.Element("competitionProperties").Elements("property")), MappedMarkets = sportElement.Element("mapping").Elements("market").Select(x => new MappedMarket() { Type = getAttrib(x, "type"), MappedType = getAttrib(x, "mappedType") }) }; } catch (Exception ex) { throw ex; } } } [Test] public void GoodConfig() { var document = new XmlDocument(); document.LoadXml(Resources.ValidSportSectionConfig); var config = new SportSection().Create(null, null, document) as dynamic; IEnumerable<dynamic> sportList = config.SportList; Assert.AreEqual(1, sportList.Count());
UPDATE - Stack Trace:
at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at SS.Integration.EVenue.WindowsService.UnitTests.Configuration.SportSectionTests.<GoodConfig>b__11(Object x) in C:\_Git\SS.Integration.EVenue\SS.Integration.EVenue.WindowsService.UnitTests\Configuration\SportSectionTests.cs:line 35
source share