如何解决异常:"Call was rejected by callee. Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))"?

How to solve exception: "Call was rejected by callee. Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))"?

使用 Microsoft.Office.Interop.Word命名空间。

Document.SaveAs2 方法不接受作为第一个参数给出的路径。


if (saveFileDialog_Docx.ShowDialog() != DialogResult.Cancel)
{
    string originalPath = Directory.GetCurrentDirectory();
    string dirpath = Path.Combine(originalPath, saveFileDialog_Docx.FileName);
    //lbl_test.Text = dirpath;
    document.SaveAs2(@""+ dirpath, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}

无论我使用 dirpath 还是 @"" + dirpath 作为第一个参数,路径都不被接受,并抛出以下异常:

Exception:Call was rejected by callee. Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

我想从 savefiledialog 获取路径。

方法SaveAs2的文档显示签名是:

public void SaveAs2 (
    ref object FileName,
    ref object FileFormat,
    ref object LockComments,
    [...]
    ref object CompatibilityMode);

说明FileName是一个ref参数。因此,你只需要在你的论点之前添加 ref ,就像你为其他人所做的那样。无需在 dirpath 变量前添加 @""

您的代码应该是:

document.SaveAs2(ref dirpath, ref missing, [...] ref missing);

https://docs.microsoft.com/fr-fr/dotnet/api/microsoft.office.tools.word.document.saveas2?view=vsto-2017