2

We have an Outlook VSTO component that adds a panel that contains a WebBrowser component, which in turn opens a web page.

We want to call back from the web page using WebBrowser.ObjectForScripting, but the guidance provided by MS here doesn't work.

So in the C# VSTO we have something like:

[ComVisible(true), 
 PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class MyComponent { ...

    webBrowser1.ObjectForScripting = this;
    webBrowser1.Document.InvokeScript("test");

    ...

    public void HandleResult() { ...

And in the JS we have something like:

function test() {
    doSomethingAsync().then(function(result) {  
        window.external.HandleResult();
    });
}

However HandleResult is never called.

I think the issue it due to the PermissionSet being denied permissions in a VSTO add-in that it does get in stand alone Windows Forms apps.

Any idea how to set the appropriate permissions?

Keith
  • 150,284
  • 78
  • 298
  • 434
  • Try adding `[ClassInterface(ClassInterfaceType.AutoDispatch)]` to `MyComponent` – noseratio Oct 23 '18 at 13:27
  • @noseratio Isn't that the default anyway? – Keith Oct 25 '18 at 06:13
  • Not sure, but I've always been using it (or rather, an explicit interface [like this](https://stackoverflow.com/a/23441190/1768303)). Did it change anything for you? Also, what if you don't specify `[PermissionSet]` at all? – noseratio Oct 25 '18 at 07:52

0 Answers0