微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

解决方法

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

原文地址:https://www.jb51.cc/csharp/91910.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐