I'm trying to set up an interop between C# and JavaScript using the WPF WebBrowser control. The C#->JavaScript calls work great so far, but I can't get the JavaScript->C# operational.
I've created a class for the object:
[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);
}
}
Note that the ComVisible
attribute.
But when I set the ObjectForScripting property in the Window_Loaded event:
webBrowser.ObjectForScripting = new BrowserClient(this);
I get the following (very confusing) exception:
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.
Needless to say, I'm pretty baffled. What is happening here?
Update: It might be worth mentioning that I'm using .NET 4.0 on Windows 8.1 with Visual Studio 2013 Express for Desktop.
I think, I know your problem - you need to make your class public
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With