I am cross-posting this question from Microsoft Community because I haven't gotten any response there, and maybe someone here can shed some light on this.
I have noticed an issue that is specific to Word 2013 when using VSTO to process a document.
The document contains an image in the header or footer that has its Layout Options set to "With Text Wrapping" with either "Behind Text" or "In Front of Text":
Using VSTO, if I open the document and then attempt to process shapes, I get the following exception:
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
I have uploaded a repro here: Word2013VstoImageFormattedInHeaderBug.zip
The relevant piece of code is in 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;
}
Here is the full exception and stacktrace:
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
The exception is thrown regardless of whether I attempt to catch it or not, and it crashes Word 2013:
This bug does not occur on Word 2016, and I can process shapes successfully. However, upgrading to Office 2016 is not an option. I am of the opinion that this requires a hotfix for Office 2013 in order for the bug to be fixed.
Is there anything I can do to get this working on Word 2013? I have tried numerous supposed fixes, including multiple repairs and re-installs of Office 2013, to no avail.
Type
of the shape instead of catching an exception when it's not a group? – Dupion