方法参数,ref不工作

时间:2016-06-20 14:52:59

标签: c# asp.net ref

我正在尝试捕获异常并将这些值传递给另一个方法,但我得到参数'1'必须与'ref'关键字一起传递一个ref或out参数必须是一个可赋值变量 abc.AbendProgram(ref string,ref System.Exception)的最佳重载方法匹配有一些无效的参数。请帮助,因为我不确定我犯了什么错误。

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);
}

1 个答案:

答案 0 :(得分:1)

AbendProgram接受一个引用字符串。传入ref“open database”时,它是一个无法分配的常量文字字符串。你需要传入一个字符串变量。