title: Get content of RunWorkerCompletedEventArgs object
body: <p>I am returning a <code>RunWorkerCompletedEventArgs</code> object and I'm trying to get the error number which I can see in the object. When I use <code>if (err.Number!= 2627){}</code> I get the following error</p>
  
  <blockquote>
    <p>'object' does not contain a definition for 'Number' and no extension
    method 'Number' accepting a first argument of type 'object' could be
    found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>Please can someone advise how I can get the objects contents (see immediate window below). </p>
  
  <p>Also please can someone explain what is actually happening here as the error indicates the object does not contain a definition for 'Number' but it looks like it does exist?</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>private void GBHworker_RunWorkerCompleted(object sender, 
               RunWorkerCompletedEventArgs e)
  {
      //update UI once worker complete his work 
      if (e.Result != null)
      {
          var err = e.Result;
          if (err.Number!= 2627) //don't want to raise error on duplicate primary key
          {
              MessageBoxButton btn = MessageBoxButton.OK;
              var result = ModernDialog.ShowMessage(e.Result.ToString(), 
                           "Error", btn);
          }
      }
  }
  </code></pre>
  
  <p><strong>ASSIGNING e:</strong></p>
  
  <pre><code>private void GBHworker_DoWork(object sender, DoWorkEventArgs e)
  {
  
    //....DB parameter setup
    try
    {
      cmd_insert.ExecuteNonQuery();
    }
    catch (Exception crap)
    {
      if (e != null)
        e.Result = crap;
    }
  
   }
  </code></pre>
  
  <p><strong>IMMEDIATE WINDOW:</strong></p>
  
  <pre><code>?err
  {"Violation of PRIMARY KEY constraint 'PK_XYZ'. Cannot insert duplicate key in object 'dbo.XYZ. The duplicate key value is (30527293868).\r\nThe statement has been terminated."}
      base {System.Data.Common.DbException}: {"Violation of PRIMARY KEY constraint 'PK_XYZ'. Cannot insert duplicate key in object 'dbo.XYZ'. The duplicate key value is (30527293868).\r\nThe statement has been terminated."}
      Class: 14
      ClientConnectionId: {*******}
      Errors: {System.Data.SqlClient.SqlErrorCollection}
      LineNumber: 1
      Number: 2627
      Procedure: ""
      Server: "*******"
      Source: ".Net SqlClient Data Provider"
      State: 1
  </code></pre>