无法使用值 C# 初始化按引用变量

Cannot initialize a by-reference variable with a value C#

出现此错误无法使用值初始化引用变量我对 C# 还很陌生,只是想修复一个废弃的开源项目。

代码如下:

private bool CertificateHandler(bool valueExist)
    {
      if (!CertMaker.rootCertExists() && !CertMaker.createRootCert() || (CertMaker.rootCertIsTrusted() ? 1 : (CertMaker.trustRootCert() ? 1 : 0)) == 0)
        return false;
      // ISSUE: explicit reference operation
      ref string local1 = @this.fiddlerCertInfos._fiddlerCert;
      if (local1 == null)
        local1 = FiddlerApplication.Prefs.GetStringPref("fiddler.certmaker.bc.cert", (string) null);
      // ISSUE: explicit reference operation
      ref string local2 = @this._fiddlerCertInfos._privateKey;
      if (local2 == null)
        local2 = FiddlerApplication.Prefs.GetStringPref("fiddler.certmaker.bc.key", (string) null);
      if (!valueExist)
        this.appRegistry.UpdateRegistry(new List<RegistryInfo>()
        {
          new RegistryInfo()
          {
            Name = "FiddlerCert",
            Value = (object) this._fiddlerCertInfos._fiddlerCert,
            RegistryValueKind = RegistryValueKind.String
          },
          new RegistryInfo()
          {
            Name = "PrivateKey",
            Value = (object) this._fiddlerCertInfos._privateKey,
            RegistryValueKind = RegistryValueKind.String
          }
        });
      return true;
    }

错误行:

ref string local1 = @this.fiddlerCertInfos._fiddlerCert;
ref string local2 = @this._fiddlerCertInfos._privateKey;

读这个:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref#ref-locals

您不能为局部引用变量分配非引用值。因此,您需要删除局部变量的 ref 关键字或在分配的值前面添加 'ref'。