-3

I am trying to catch an Exception and pass those values to another method but I am getting Argument '1' must be passed with 'ref' keyword, A ref or out argument must be an assignable variable and the best overloaded method match for abc.AbendProgram(ref string, ref System.Exception) has some invalid arguments. please help as I am not sure what mistake I am making.

private void OpenDatabases()
{

     try
     {
          WinDSSS.connectionString = 
          ConfigurationManager.AppSettings["WinDSS_Connection"].Replace("%DrivePath%", DrivePath);

     }
     catch (Exception ex)
     {
          logger.AddEntry(TFSUtilities.Logger.EventType.Fatal, 
                    "frmMain.OpenDatabases", "Exception", ref ex);
          AbendProgram(ref "Open Database", ref ex);
     }

}

private void AbendProgram(ref string theRoutine, ref Exception theException)
{
     int errorNumber = -1;
     string ErrorDesc = "Unknown Error";
     if ((theException != null))
     {
          errorNumber = 9999;
          ErrorDesc = theException.ToString();
          if ((theException.InnerException != null))
          {
               ErrorDesc = ErrorDesc + Constants.vbCrLf + 
                          theException.InnerException.Message;
          }
     }

     System.Windows.Forms.MessageBox.Show("There was an error in RSCShell:" +
          theRoutine + Constants.vbLf + Constants.vbLf + Constants.vbLf + 
          "Error " + errorNumber + " - " + ErrorDesc + 
          Constants.vbLf + Constants.vbLf + "Please contact SUPPORT to resolve this issue");
     System.Environment.Exit(0);
}
Steve
  • 213,761
  • 22
  • 232
  • 286
CodeMan
  • 133
  • 3
  • 19
  • 2
    Create a string variable and supply this to your "AbendProgram" method. The error message is telling you what's wrong. A ref or out argument must be an assignable variable. I'd recommend you remove ref from the method definition altogether - you're not using it correctly. – Davie Brown Jun 20 '16 at 14:55
  • 5
    The parameters don't need to be ref parameters. You never change their values inside the method anyway. – Dennis_E Jun 20 '16 at 14:57
  • As @Dennis_E points out, why are you using the `ref` keyword at all? – Chris Dunaway Jun 20 '16 at 18:25

1 Answers1

1

AbendProgram takes a ref string. when you pass in ref "open database" that is a constant literal string that can't be assigned to. You'll need to pass in a string variable instead.

Martin Brown
  • 24,692
  • 14
  • 77
  • 122