<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Journey to the Center of the Web</title><subtitle type="html">Working in the cloud, living on the west coast, and other things that are me.</subtitle><id>http://blogs.msdn.com/mark/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mark/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/mark/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-11-18T08:58:00Z</updated><entry><title>Anonymous Types and Silverlight DataBinding</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mark/archive/2008/11/18/anonymous-types-and-silverlight-databinding.aspx" /><id>http://blogs.msdn.com/mark/archive/2008/11/18/anonymous-types-and-silverlight-databinding.aspx</id><published>2008-11-18T19:58:00Z</published><updated>2008-11-18T19:58:00Z</updated><content type="html">&lt;P&gt;My journey through working in the web world has taken me many places in the past: Cold Fusion, PHP, Classic ASP all the way to the latest version of &lt;A target=_blank href="http://www.silverlight.net/" mce_href="http://www.silverlight.net"&gt;Silverlight&lt;/A&gt;.&amp;nbsp; I'll post some of the small things I come across as I'm learning this new technology in part to document my learning process but hopefully more to help out anyone else who runs into the same issues.&amp;nbsp; My first victim, this exception:&lt;/P&gt;&lt;CODE&gt;
&lt;P mce_keep="true"&gt;An unhandled exception 'Unhandled Error in Silverlight 2 Application Code: 4004 Category ManagedRuntimeError Message: System.MethodAccessException: &amp;lt;&amp;gt;f__AnonymousType0`.get_Summary()&lt;/P&gt;&lt;/CODE&gt;
&lt;P mce_keep="true"&gt;I ran into this while&amp;nbsp;writing a quick prototype trying learning all the pieces of silverlight.&amp;nbsp; My first app was an xml feed reader with code similar to this:&lt;/P&gt;&lt;CODE&gt;
&lt;P mce_keep="true"&gt;[get xml feed content into and XDocument called feed]&lt;/P&gt;
&lt;P mce_keep="true"&gt;CustomFeedItemControl.FeedItem&amp;nbsp;= from item in feed.Element("item") select new { Title = item.Element("title").Value, Summary = item.Element("description").Value };&lt;/P&gt;&lt;/CODE&gt;
&lt;P mce_keep="true"&gt;The first thing that comes up on searches is information on the &lt;A target=_blank href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx" mce_href="http://blogs.msdn.com/shawnfa/archive/2007/05/09/the-silverlight-security-model.aspx"&gt;Silverlight security model&lt;/A&gt;.&amp;nbsp; Any calls made from security transparent code to critical code will throw a MethodAcessException.&amp;nbsp; The second clue here is the "get_Summary()" part of the exception.&amp;nbsp; Remember that in C# properties are really just syntactic sugar for accessor/modifier methods for a field and internally the get_ and set_ methods are created for interoperability with other .Net languages.&amp;nbsp; So basically, there's a security exception trying to access the property on the anonymous typed class.&amp;nbsp; But why?&lt;/P&gt;
&lt;P mce_keep="true"&gt;Well this occurs because anonymous objects are typed as internal.&amp;nbsp; Silverlight will not reflect on private members as part of its security model and throws this exception.&amp;nbsp; One solution for my example is to create some kind of public type "FeedItem" with properties Title, Summary, etc.&amp;nbsp; In my next post I'll talk about a better solution for dealing with feeds altogether.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9119341" width="1" height="1"&gt;</content><author><name>mdefalco</name><uri>http://blogs.msdn.com/members/mdefalco.aspx</uri></author></entry></feed>