加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 04:21:14 所属栏目:百科 来源:网络整理
导读:我正在尝试使用 WPF WebBrowser控件在C#和 JavaScript之间建立互操作.到目前为止,C# – JavaScript调用工作得很好,但我无法使JavaScript- C#运行. 我为对象创建了一个类: [ComVisible(true)]class BrowserClient{ private MainWindow owner; public string
我正在尝试使用 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.

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读