title: c# cast multi column listbox back to struct
body: <p>I have a multi column listbox, which gets filled with structs: </p>
  
  <pre class="lang-cs prettyprint-override"><code>List&lt;SoftwareAssetStruct&gt; software = new List&lt;SoftwareAssetStruct&gt;();
  foreach (DataRow dataRow in dt.Rows)
  {
      software.Add(new SoftwareAssetStruct()
      {
          Softwareid = dataRow["id"].ToString(),
          Softwarename = dataRow["software_name"].ToString(),
          Softwareversion = dataRow["software_version"].ToString(),
          Softwaregroup = dataRow["software_group"].ToString(),
          Softwarelicensenr = dataRow["software_license_nr"].ToString()
      });
  
  }
  
  softListBox.ItemsSource = software;
  softListBox.SelectionMode = SelectionMode.Multiple;
  </code></pre>
  
  <p>After the selection is done, I navigate to a new Page.</p>
  
  <pre class="lang-cs prettyprint-override"><code>private void SelectSoftware(object sender, RoutedEventArgs e)
  {            
      NavigationService.Navigate(new MailPage(softListBox)); 
  }
  </code></pre>
  
  <p>Now I´m able to visualize those entries, but I´m not able to cast the back to a struct so I can access the separate Data-Fields </p>
  
  <pre class="lang-cs prettyprint-override"><code>public MailPage(ListBox lbx)
  {
      InitializeComponent();
      Array komisch;
  
      if (lbx != null)
      {
          for (int i = 0; i &lt; lbx.SelectedItems.Count; i++)
          {
              softListBox12.Items.Add(lbx.SelectedItems[i]);
  
          }
      }
  
      foreach( SoftwareAssetStruct structAsset in softListBox12.Items)
      {
          MessageBox.Show(structAsset.Softwarename);
  
      }
  }
  </code></pre>
  
  <p>I have defined such structs on both pages: </p>
  
  <pre class="lang-cs prettyprint-override"><code>private class SoftwareAssetStruct
  {
      public string Softwareid { get; set; }
  
      public string Softwarename { get; set; }
  
      public string Softwareversion { get; set; }
  
      public string Softwaregroup { get; set; }
  
      public string Softwarelicensenr { get; set; }
  }
  </code></pre>
  
  <p>When I try to Cast it back I get this Error Message: </p>
  
  <blockquote>
    <p>System.InvalidCastException: "[A]SoftwareAssetStruct cannot be cast to [B]SoftwareAssetStruct. Type A originates from 'Share-Me, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Users\XXX\source\repos\Share-Me\Share-Me\bin\Debug\netcoreapp3.0\Share-Me.dll'. Type B originates from 'Share-Me, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Users\XXX\source\repos\Share-Me\Share-Me\bin\Debug\netcoreapp3.0\Share-Me.dll'."</p>
  </blockquote>