c# – WebBrowser在ObjectForScripting上声称“对象类型对COM不可见”

我正在尝试使用 WPF Webbrowser控件在C#和 JavaScript之间建立互操作.到目前为止,C# – > JavaScript调用工作得很好,但我无法使JavaScript-> C#运行.

我为对象创建一个类:

[ComVisible(true)]
class browserClient
{
    private MainWindow owner;

    public string id = "browser-client";

    public browserClient(MainWindow owner)
    {
        this.owner = owner;
    }

    public void sendMessage(string date)
    {
        owner.OnReceiveMessage(date);
    }
}

请注意ComVisible属性.

但是当我在Window_Loaded事件中设置ObjectForScripting属性时:

webbrowser.ObjectForScripting = new browserClient(this);

我得到以下(非常混乱)异常:

An unhandled exception of type ‘System.ArgumentException’ occurred in
PresentationFramework.dll

Additional information: The object type is not visible to COM. You
need to set ComVisibleAttribute attribute to True.

不用说,我很困惑.这里发生了什么?

更新:值得一提的是,我在Windows 8.1上使用.NET 4.0和Visual Studio 2013 Express for Desktop.

解决方法

我想,我知道你的问题 – 你需要公开你的课程

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...