BUG: Word 2013 VSTO Cannot Handle Image in Header Formatted Behind - Microsoft Community


i have noticed issue specific word 2013 when using vsto process document.

the document contains image in header or footer has layout options set "with text wrapping" either "behind text" or "in front of text":

using vsto, if open document , attempt process shapes, following exception:

the remote procedure call failed. (exception hresult: 0x800706be)

i have uploaded repro here: word2013vstoimageformattedinheaderbug.zip

the relevant piece of code in wordfieldenumerator.cs:

private static bool shapeswithingroup(shape shape)
{
    var result = false;
    try
    {
        if (shape.groupitems != null && shape.groupitems.count > 0) // shape.groupitems throws exception
        {
            result = true;
        }
    }
    catch (unauthorizedaccessexception)
    {
        // shape not in group - ignore
    }
    catch (exception exception)
    {
        var exceptionstring = exception.buildexceptionstring();
        console.writeline(exceptionstring);
        console.writeline(exception.stacktrace);
        //throw;
    }

    return result;
}

here full exception , stacktrace:

the remote procedure call failed. (exception hresult: 0x800706be)

   @ microsoft.office.interop.word.shape.get_groupitems()
   @ word2013vstoimageformattedinheaderbug.wordfieldenumerator.shapeswithingroup(shape shape) in c:\users\qa\desktop\word2013vstoimageformattedinheaderbug\word2013vstoimageformattedinheaderbug\wordfieldenumerator.cs:line 170
rpc server unavailable. (exception hresult: 0x800706ba)

   @ microsoft.office.interop.word.shape.get_textframe()
   @ word2013vstoimageformattedinheaderbug.wordfieldenumerator.processshapes(ienumerable`1 shapes) in c:\users\qa\desktop\word2013vstoimageformattedinheaderbug\word2013vstoimageformattedinheaderbug\wordfieldenumerator.cs:line 124
rpc server unavailable. (exception hresult: 0x800706ba)

   @ system.runtime.interopservices.marshal.throwexceptionforhrinternal(int32 errorcode, intptr errorinfo)
   @ system.runtime.interopservices.custommarshalers.enumeratorviewofenumvariant.movenext()
   @ system.linq.enumerable.<castiterator>d__aa`1.movenext()
   @ word2013vstoimageformattedinheaderbug.wordfieldenumerator.processshapes(ienumerable`1 shapes) in c:\users\qa\desktop\word2013vstoimageformattedinheaderbug\word2013vstoimageformattedinheaderbug\wordfieldenumerator.cs:line 90
   @ word2013vstoimageformattedinheaderbug.wordfieldenumerator.getallfields() in c:\users\qa\desktop\word2013vstoimageformattedinheaderbug\word2013vstoimageformattedinheaderbug\wordfieldenumerator.cs:line 64
   @ word2013vstoimageformattedinheaderbug.program.lockdialogfields(document document) in c:\users\qa\desktop\word2013vstoimageformattedinheaderbug\word2013vstoimageformattedinheaderbug\program.cs:line 116
   @ word2013vstoimageformattedinheaderbug.program.pdfdocument(string documentfilepath) in c:\users\qa\desktop\word2013vstoimageformattedinheaderbug\word2013vstoimageformattedinheaderbug\program.cs:line 60

the exception thrown regardless of whether attempt catch or not, , crashes word 2013:

this bug not occur on word 2016, , can process shapes successfully. however, upgrading office 2016 not option. of opinion requires hotfix office 2013 in order bug fixed.

is there can working on word 2013? have tried numerous supposed fixes, including multiple repairs , re-installs of office 2013, no avail.

awaiting response,

~sam.

as answered here, solution select range contains image in header (or footer) first before attempting access shapes:

    foreach (headerfooter header in section.headers)
    {
        if (header.linktoprevious) // || header.index != wdheaderfooterindex.wdheaderfooterfirstpage
        {
            continue;
        }

        header.range.select(); // line fixes issue

        // add fields in header
        fields.addrange(header.range.fields.cast<field>());

        // add fields in shapes in header
        var fieldsinshapes = processshapes(header.shapes.cast<shape>());
        fields.addrange(fieldsinshapes);
    }

    foreach (headerfooter footer in section.footers)
    {
        if (footer.linktoprevious) // || footer.index != wdheaderfooterindex.wdheaderfooterfirstpage
        {
            continue;
        }

        footer.range.select(); // line fixes issue

        // add fields in footer
        fields.addrange(footer.range.fields.cast<field>());

        // add fields in shapes in footer
        var fieldsinshapes = processshapes(footer.shapes.cast<shape>());
        fields.addrange(fieldsinshapes);
    }

it's silly, , non-obvious, , frustrating, @ least there is solution.



Office / Unknown/other / Microsoft Office Programming / Office 2013



Comments

Popular posts from this blog

message deleted by transport agent, event: LED=550 4.3.2 - Microsoft Community

Outlook conversion problem - Microsoft Community

Outlook 2016 - Insert attachment to Meeting Invite You Do Not Own - Microsoft Community