I cross-post this question from the Microsoft community because I did not get any answer there, and maybe someone here can shed some light on this.
I noticed a problem that applies to Word 2013 when using VSTO to process a document.
The document contains an image in the header or footer, in which its layout settings are set to “With text wrap” using “Behind text” or “Before text”:

Using VSTO, if I open a document and then try to process the shapes, I get the following exception:
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
I uploaded the reproduction here: Word2013VstoImageFormattedInHeaderBug.zip
The corresponding code snippet 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 complete 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
An exception is thrown regardless of whether I try to catch it or not, and it resets Word 2013:

This error does not occur in Word 2016, and I can successfully process forms. However, upgrading to Office 2016 is not an option. I believe that fixing a bug requires a fix for Office 2013.
Is there anything I can do to make this work in Word 2013? I tried many alleged fixes, including several repairs and reinstallations of Office 2013, but to no avail.
c # ms-word word-2013 vsto com-interop
Sameer singh
source share