title: WPF. Unable to cast object of type
body: <p>Hello guys i have collection : </p>
  
  <pre><code>public class ActionData
  {
      private int iD;
  
      public int ID 
      {
          get { return iD; }
          set { iD = value; }
      }
      private string roomType;
  
      public string RoomType 
      {
          get { return roomType; }
          set { roomType = value; }
      }
  }
  </code></pre>
  
  <p>like this</p>
  
  <pre><code>private void btnGridToExcel_Click(object sender, RoutedEventArgs e)
  {
      ExportExcel&lt;ActionData, ActionDatas&gt; exp = new ExportExcel&lt;ActionData, ActionDatas&gt;();
      exp.GenerateReport();
      ICollectionView view = CollectionViewSource.GetDefaultView(dataGrid1.ItemsSource);
      exp.dataToPrint = (ActionDatas)view.SourceCollection;
      exp.GenerateReport(); 
  }
  </code></pre>
  
  <p>On this button click must export data to excel but i gives such error on  <code>exp.dataToPrint = (ActionDatas)view.SourceCollection;</code>:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Collections.ObjectModel.ObservableCollection`1[H_Pro.Logicstic+ActionData]' to type 'ActionDatas'.</p>
  </blockquote>
  
  <p>Here is a some part of method which gets values </p>
  
  <pre><code> public class ActionDatas : List&lt;ActionData&gt; { }
  
          #region toxls
           public class ExportExcel&lt;T, U&gt;
          where T : class
          where U : List&lt;T&gt;
      {
          public List&lt;T&gt; dataToPrint;
  </code></pre>
  
  <p>does anyone have an idea why im getting such error?</p>