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 Silverlight.  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.  My first victim, this exception:

An unhandled exception 'Unhandled Error in Silverlight 2 Application Code: 4004 Category ManagedRuntimeError Message: System.MethodAccessException: <>f__AnonymousType0`.get_Summary()

I ran into this while writing a quick prototype trying learning all the pieces of silverlight.  My first app was an xml feed reader with code similar to this:

[get xml feed content into and XDocument called feed]

CustomFeedItemControl.FeedItem = from item in feed.Element("item") select new { Title = item.Element("title").Value, Summary = item.Element("description").Value };

The first thing that comes up on searches is information on the Silverlight security model.  Any calls made from security transparent code to critical code will throw a MethodAcessException.  The second clue here is the "get_Summary()" part of the exception.  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.  So basically, there's a security exception trying to access the property on the anonymous typed class.  But why?

Well this occurs because anonymous objects are typed as internal.  Silverlight will not reflect on private members as part of its security model and throws this exception.  One solution for my example is to create some kind of public type "FeedItem" with properties Title, Summary, etc.  In my next post I'll talk about a better solution for dealing with feeds altogether.