title: The specified Cast is not a valid
body: <p>I would appreciate some help debugging this please. I have a stored proc as defined below </p>
  
  <pre><code>ALTER PROCEDURE [dbo].[usp_ProcessBoxNumberPaymentInfo_Test]
      -- Add the parameters for the stored procedure here
       @boxNumber int, 
       @ProcessDate DateTime,
       @BoxType Varchar(50),
       @PaymentProcessDate DateTime,
       @Identity int OUTPUT  
  
  BEGIN 
      Declare @NewID as int 
    -- INSERT CODE GOES HERE
  
     Set @NewID = SCOPE_IDENTITY()
    -- ANOTHER INSERT CODE GOES HERE
         SELECT @Identity = SCOPE_IDENTITY()  
  
  END
  </code></pre>
  
  <p>On the code side, I have the following method in my DataContext class to execute my storedproc, passing the valids specified. </p>
  
  <pre><code> [global::System.Data.Linq.Mapping.FunctionAttribute(Name = "dbo.usp_ProcessBoxNumberPaymentInfo_Test")]
          public int GetValidPaymentBoxNumberLogID_Test(
              [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "boxNumber", DbType = "Int")] string boxNumber,
              [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "ProcessDate", DbType = "DateTime")] DateTime ProcessDate,
              [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "BoxType", DbType = "VarChar(50)")] string BoxType,
              [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "PaymentProcessDate", DbType = "DateTime")] DateTime PaymentProcessDate,
              [global::System.Data.Linq.Mapping.ParameterAttribute(Name = "Identity", DbType = "Int")] ref System.Nullable&lt;int&gt; identity)
          {
              IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), boxNumber, ProcessDate, BoxType, PaymentProcessDate, identity);
              identity = ((System.Nullable&lt;int&gt;)(result.GetParameterValue(4)));
              return ((int)(result.ReturnValue));
          }
  </code></pre>
  
  <p>Problem I am having is when I run the code, I get the following exception </p>
  
  <p><strong>The specified Cast is not a valid</strong></p>
  
  <p>This error is thrown at line <strong>return ((int)(result.ReturnValue));</strong>  I am not entirely sure what type is missing and where. Really, any help figuring this out will be greatly appreciated. Thanks in advance. </p>