title: Why does one class need a Data Contract Attribute and the other does not
body: <p>I am using .NET Web API and of course returning classes that are serialized to JSON. Up Until now I have not had to use the Data Contract attribute for any classes, but for this class below I do and I have no idea why. Intellitrace just says the class is unable to be serialized and to try adding a DataContract Attribute. I will but want to know why.</p>
  
  <pre><code>public class Card : BaseGridVM
  {
  
      private IEnumerable&lt;Pc&gt; _pcCards;
      private IEnumerable&lt;Pt&gt; _ptCards;
      private IEnumerable&lt;MembershipCard&gt; _membershipCards;
  
      public Grid.Result Pt
      {
          get { return GetPtCardGrid(); }
      }
      public Grid.Result Pc
      {
          get { return GetPcCardGrid(); }
      }
      public Grid.Result Membership
      {
          get { return GetMembershipCardGrid(); }
      }
  
      public Card(IEnumerable&lt;Pc&gt; pcCards, IEnumerable&lt;Pt&gt; ptCards, IEnumerable&lt;MembershipCard&gt; membershipCards)
      {
          _pcCards = pcCards;
          _ptCards = ptCards;
          _membershipCards = membershipCards;
      }
  
      private Grid.Result GetPtCardGrid()
      {
          var headers = new List&lt;Grid.Header&gt;
                            {
                                new Grid.Header() {label = "Card Name", width = 250},
                                new Grid.Header() {label = "Pts", width = 50},
                                new Grid.Header() {label = "Activation Date", width = 50}
                            };
  
          var rows = new List&lt;Grid.Row&gt;();
          foreach (var card in _ptCards)
          {
              var row = new Grid.Row
              {
                  id = card.id,
                  enabled = card.active.HasValue &amp;&amp; (bool)card.active,
                  cell = new string[3]
              };
  
              row.cell[0] = card.cardName;
              row.cell[1] = card.pts.HasValue ? card.pts.ToString() : "0";
              row.cell[2] = card.activationDate.HasValue ? card.activationDate.ToString() : "-";
  
              rows.Add(row);
          }
  
          return buildGrid(rows, headers, 1, 3);
      }
  
      private Grid.Result GetPcCardGrid()
      {
          var headers = new List&lt;Grid.Header&gt;
                            {
                                new Grid.Header() {label = "Offer Title", width = 200},
                                new Grid.Header() {label = "Pces Required", width = 70},
                                new Grid.Header() {label = "Activation Date", width = 50}
                            };
  
          var rows = new List&lt;Grid.Row&gt;();
          foreach (var card in _pcCards)
          {
              var row = new Grid.Row
              {
                  id = card.id,
                  enabled = card.active.HasValue &amp;&amp; (bool)card.active,
                  cell = new string[3]
              };
  
              row.cell[0] = card.cardName;
              row.cell[1] = card.pces.HasValue ? card.pces.ToString() : "0";
              row.cell[2] = card.creationDate.HasValue ? card.creationDate.ToString() : "-";
  
              rows.Add(row);
          }
  
          return buildGrid(rows, headers, 1, 3);
      }
  
      private Grid.Result GetMembershipCardGrid()
      {
          var headers = new List&lt;Grid.Header&gt;
                            {
                                new Grid.Header() {label = "Card Name", width = 200},
                                new Grid.Header() {label = "Members", width = 70}
                            };
  
          var rows = new List&lt;Grid.Row&gt;();
          foreach (var card in _membershipCards)
          {
              var row = new Grid.Row
              {
                  id = card.id,
                  enabled = card.active.HasValue &amp;&amp; (bool)card.active,
                  cell = new string[2]
              };
  
              row.cell[0] = card.cardName;
              row.cell[1] = card.membersCount.HasValue ? card.membersCount.ToString() : "0";
  
              rows.Add(row);
          }
  
          return buildGrid(rows, headers, 1, 3);
      }
  }
  </code></pre>
  
  <p>This is Base GridVM</p>
  
  <pre><code> public abstract class BaseGridVM
  {
      protected static Grid.Result buildGrid(IEnumerable&lt;Grid.Row&gt; rows, IEnumerable&lt;Grid.Header&gt; headers, int page, int steps)
      {
          var row_array = rows.ToArray();
          var result = new Grid.Result
          {
              rows = row_array,
              page = page,
              records = row_array.Count(),
              steps = steps,
              headers = headers.ToArray()
          };
          return result;
      }
  }
  </code></pre>
  
  <p>And this is another Class where a Data Contract is not requested</p>
  
  <p>public class DashboardVM : IDashboardVM
      {</p>
  
  <pre><code>    public IResults_Dashboard results { get; private set; }
      public Grid.Result topCompaniesGrid
      {
          get { return BuildTopCompanies(); }
      }
      public Grid.Result topAdsGrid
      {
          get { return BuildTopAds(); }
      }
  
      public DashboardVM(IResults_Dashboard results)
      {
          this.results = results;
      }
      private static Grid.Result buildGrid(IEnumerable&lt;Grid.Row&gt; rows, IEnumerable&lt;Grid.Header&gt; headers, int page, int steps)
      {
          var row_array = rows.ToArray();
          var result = new Grid.Result
                           {
                               rows = row_array,
                               page = page,
                               records = row_array.Count(),
                               steps = steps,
                               headers = headers.ToArray()
                           };
          return result;
      }
  
      private Grid.Result BuildTopCompanies()
      {
          var headers = new List&lt;Grid.Header&gt;
                            {
                                new Grid.Header() {label = "Company Name", width = 150, click = true},
                                new Grid.Header() {label = "Coupon Views", width = 50, click = true},
                                new Grid.Header() {label = "Coupon Clicks", width = 50},
                                new Grid.Header() {label = "Coupon Redemptions", width = 50},
                                new Grid.Header() {label = "Ad Views", width = 50, click = true},
                                new Grid.Header() {label = "Ad Clicks", width = 50},
                                new Grid.Header() {label = "Reward Cards", width = 50},
                                new Grid.Header() {label = "Fees", width = 50}
                            };
  
          var rows = new List&lt;Grid.Row&gt;();
          foreach (var company in results.companies)
          {
              var row = new Grid.Row {id = Convert.ToInt32(company.companyId), cell = new string[8]};
  
              row.cell[0] = company.companyName;
              row.cell[1] = company.couponViews.ToString();
              row.cell[2] = company.couponClicks.ToString();
              row.cell[3] = company.couponRedemptions.ToString();
              row.cell[4] = company.adViews.ToString();
              row.cell[5] = company.adClicks.ToString();
              row.cell[6] = company.rewardCards.ToString();
              row.cell[7] = company.revenue.ToString();
  
              rows.Add(row);
          }
  
          return buildGrid(rows, headers, 1, 3);
      }
  
      private Grid.Result BuildTopAds()
      {
          var headers = new List&lt;Grid.Header&gt;
                            {
                                new Grid.Header() {label = "Company Name", width = 150, click = true},
                                new Grid.Header() {label = "Ad Name", width = 150, click = true},
                                new Grid.Header() {label = "Views", width = 50},
                                new Grid.Header() {label = "Clicks", width = 50},
                                new Grid.Header() {label = "Fees", width = 50}
                            };
  
          var rows = new List&lt;Grid.Row&gt;();
          foreach (var ad in results.ads)
          {
              var row = new Grid.Row {id = Convert.ToInt32(ad.Id), cell = new string[5]};
  
              row.cell[0] = ad.companyName;
              row.cell[1] = ad.name;
              row.cell[2] = ad.views.ToString();
              row.cell[3] = ad.clicks.ToString();
              row.cell[4] = ad.fees.ToString();
  
              rows.Add(row);
          }
  
          return buildGrid(rows, headers, 1, 3);
      }
  }
  </code></pre>