title: AnonymousType cannot be serialized. Consider marking it with the DataContractAttribute attribute
body: <p>I have a Web API and I'm just trying to return some data to the calling client in XML format.</p>
  
  <p>I keep getting the following error:</p>
  
  <pre><code>&lt;ExceptionMessage&gt;
  Type '&lt;&gt;f__AnonymousType7`9[System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.Nullable`1[System.Int32],System.String]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
  &lt;/ExceptionMessage&gt;
  </code></pre>
  
  <p>Here's the Controller code:</p>
  
  <pre><code>public class TribuneShowsController : ApiController
      {
          private readonly TVDataEntities db;
  
          public TribuneShowsController()
          {
              db = new TVDataEntities();
              db.Configuration.ProxyCreationEnabled = false;
          }
  
          public IEnumerable GetTribuneShows(string title = null,
                                             string genre = null,
                                             string showTypeDescription = null,
                                             string directorName = null,
                                             string releaseYear = null)
          {
              var query = from shows in db.TRIB_Shows
                          from showTypes in
                              db.TRIB_LKP_ShowTypes.Where(v =&gt; v.ShowTypeCode == shows.ShowTypeCode).DefaultIfEmpty()
                          select new
                              {
                                  dataSource = "Tribune",
                                  shows.Title,
                                  EpisodeId = "",
                                  EpisodeTitle = "",
                                  Genre = shows.Category,
                                  showTypes.ShowTypeDescription,
                                  shows.DirectorName,
                                  shows.ReleaseYear,
                                  SeasonEpisode = ""
                              };
  
              if (title != null)
              {
                  query = query.Where(s =&gt; s.Title.Contains(title));
              }
  
              if (genre != null)
              {
                  query = query.Where(s =&gt; s.Genre.Contains(genre));
              }
  
              if (showTypeDescription != null)
              {
                  query = query.Where(s =&gt; s.ShowTypeDescription.Contains(showTypeDescription));
              }
  
              if (directorName != null)
              {
                  query = query.Where(s =&gt; s.DirectorName.Contains(directorName));
              }
  
              if (releaseYear != null)
              {
                  query = query.Where(s =&gt; s.ReleaseYear.ToString().Contains(releaseYear));
              }
  
              return query.ToList();
          }
  
          protected override void Dispose(bool disposing)
          {
              db.Dispose();
              base.Dispose(disposing);
          }
      }
  </code></pre>
  
  <p>My first question is, how do I default the return object (by the API) to XML? So whenever someone goes to the link, they'll get an XML.</p>
  
  <p>Second question is, how do I go about returning the anonymous type in my code above as an XML to the client?</p>