1
votes

I'm developing an add-in for Microsoft Word 2016 using office js version 16.0.8626.1000. I use a web service to retrieve a document in base64 format and then I create a new Word instance with that.

The problem is that whenever I run the add-in from my server (not from visual studio debugger) it opens the document but the add-in frame displays an error

First Instance: First office instance

Second Instance: Second instance with document retrieved from WS

This doesn't happen if I run the add-in from visual studio debugger, it opens the new instance without the frame.

This is my code

Office.initialize = function (reason) {
    // Checks for the DOM to load using the jQuery ready function.
    $(document).ready(function () {
        $('#get').click(function () {
            openWord();
        });
    });
}

This how I retrieve the document (without real url):

function openWord() {
    getDocumentAsBase64(function (data) {
        Word.run(function (context) {
            var myNewDoc = context.application.createDocument(data);
            context.load(myNewDoc);

            return context.sync()
                .then(function () {
                    myNewDoc.open();
                    context.sync();
                })
                .catch(function (myError) {
                    //otherwise we handle the exception here!
                    updateStatus(myError.message);
                })
        }).catch(function (myError) {
            updateStatus(myError.message);
        });
    });
}

function getDocumentAsBase64(callback) {
    $.ajax({
        url: 'http://myurltomydocument.com/getFile',
        data: "{}",
        dataType: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        success: function (response) {
            callback(response.d);
        },
        error: function (response) {
            updateStatus(response.d);
        }
    });
}

EDIT -- 8/12/2017

This is the manifest that I'm currently using if anyone wants to replicate the problem with Office 2016

2

2 Answers

0
votes

I don't read Spanish, but the error mentions Visual Studio. I think Office is still trying to run a version that was sideloaded with Visual Studio and it's telling you that it can't do that. The problem might be the manifest. I notice that it still has the string ~remoteAppUrl in many places. When you are debugging with VS, this string is automatically replaced with the localhost URL, but you need to manually change all these to your web service's domain and sideload the new manifest when you are going to run it from the web service.

EDIT 12/11/17: If that doesn't fix it, try clearing the Office cache. Details are at: Clear the Office cache

Edit 12/19/17: Try this:
Go on File->Info->Check for Issues -> Inspect Document -> Inspect. Then on Task Pane Add-ins click Remove All

0
votes

Finally I found the solution to this problem.

  1. First I downloaded Office 2016 Administrative Template Files. When you run it, it will extract a bunch of files and folders.
  2. Enter admx folder and copy the whole content to C:\Windows\PolicyDefinitions.
  3. Do a gpupdate /force under CMD (or Powershell) as an administrator.
  4. Run gpedit.msc and find the Administrative Template for Office 2016 then Updates (PC configuration >> Administrative Template >> Microsoft Office 2016 >> Updates >> Update Channel) and set the Update Channel to Montly Channel.

I'm on Version 1711 (compilation 8730.2127 click and run) and everything is working good now.

EDIT 9/1/2018: The error started showing up again. The only thing I did was attaching the runtime logging to debug my add-in manifest. This is still unsolved.