我从 Microsoft 社区交叉发布了这个问题,因为我在那里没有得到任何回复,也许这里有人可以对此有所了解。
在使用 VSTO 处理文档时,我注意到 Word 2013 特有的问题。
该文档在页眉或页脚中包含一个图像,其布局选项设置为“带文本环绕”,“文本后”或“文本前”:
使用 VSTO,如果我打开文档然后尝试处理形状,则会收到以下异常:
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
我在这里上传了一个重现:Word2013VstoImageFormattedInHeaderBug.zip
相关的代码在WordFieldEnumerator.cs
:
private static bool ShapesWithinGroup(Shape shape)
{
var result = false;
try
{
// shape.GroupItems throws the exception
if (shape.GroupItems != null && shape.GroupItems.Count > 0)
{
result = true;
}
}
catch (UnauthorizedAccessException)
{
// This shape is not in a group - ignore
}
catch (Exception exception)
{
var exceptionString = exception.BuildExceptionString();
Console.WriteLine(exceptionString);
Console.WriteLine(exception.StackTrace);
//throw;
}
return result;
}
这是完整的异常和堆栈跟踪:
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
at Microsoft.Office.Interop.Word.Shape.get_GroupItems()
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.ShapesWithinGroup(Shape shape) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 170
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
at Microsoft.Office.Interop.Word.Shape.get_TextFrame()
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.ProcessShapes(IEnumerable`1 shapes) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 124
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.ProcessShapes(IEnumerable`1 shapes) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 90
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.GetAllFields() in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 64
at Word2013VstoImageFormattedInHeaderBug.Program.LockDialogFields(Document document) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\Program.cs:line 116
at Word2013VstoImageFormattedInHeaderBug.Program.PdfDocument(String documentFilePath) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\Program.cs:line 60
无论我是否尝试捕获它,都会引发异常,并且它会使 Word 2013 崩溃:
Word 2016 上不会出现此错误,我可以成功处理形状。但是,不能升级到 Office 2016。我认为这需要 Office 2013 的修补程序才能修复该错误。
我能做些什么来让它在 Word 2013 上运行吗?我尝试了许多假定的修复程序,包括多次修复和重新安装 Office 2013,但均无济于事。