NonComVisibleBaseClass

Add-in Express™ Support Service
That's what is more important than anything else

NonComVisibleBaseClass
Need to pass data from Javascipt in WebBrowser Control to Word Add-In 
Jeffrey Childers


Guest


I am upgrading an Add-In Express generated add-in tothe latest of your .net product. In my add-in, I have a basic webpage that calls Window.External.fillForm(data);

I have a Form created through Add-In Express with a web browser control on it.

Here is my code:

namespace WordAddIn
{

public partial class TemplateForm: AddinExpress.WD.ADXWordTaskPane
{
public TemplateForm()
{
InitializeComponent();
webBrowser1.ObjectForScripting = this;
//webBrowser1.ScriptErrorsSuppressed = true;
}
public void fillForm(string matterData)
{
Do Something with data from JScript
}


So, I have tried this with or without ComVisible(true) on the class. No luck.

Here is the error that I am getting:

Managed Debugging Assistant 'NonComVisibleBaseClass' has detected a problem in 'C:\Program Files (x86)\Microsoft Office\Root\Office16\WinWord.exe'.

Additional information: A QueryInterface call was made requesting the default IDispatch interface of COM visible managed class 'WordAddIn.TemplateForm'. However since this class does not have an explicit default interface and derives from non COM visible class 'AddinExpress.Extensions.ADXForm', the QueryInterface call will fail. This is done to prevent the non COM visible base class from being constrained by the COM versioning rules.

How do I work around this error?

BTW: This worked just fine in
Posted 01 Sep, 2016 17:51:11 Top
Jeffrey Childers


Guest


I have resolved this and want to share my results.

To expose C# functions to javascript on a page displayed in a web browser control, you need to move the function outside of AddinExpress.WD.ADXWordTaskPane.

It is very easy. Just create a separate public class and decorate with ComVisible as below.

namespace WordAddIn.Helpers
{
[ComVisible(true)]
public class ExposedFunctions
{
public void InvokeAction()
{
MessageBox.Show("Hello");
}

Then, in the AddinExpress.WD.ADXWordTaskPane, after initializing the TaskPane do this:

public partial class TemplateForm: AddinExpress.WD.ADXWordTaskPane
{
public TemplateForm()
{
InitializeComponent();

webBrowser1.ObjectForScripting = new Helpers.ExposedFunctions();
Posted 02 Sep, 2016 00:28:53 Top
Marcus Datascout


Guest


Hi Jeffrey,

That's very useful.

Thanks for taking the time to share.

Cheers - Marcus
Posted 02 Sep, 2016 02:38:22 Top