Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ObjectForScript与多个接口不工作_C#_Javascript_Winforms_Interface_Comvisible - Fatal编程技术网

C# ObjectForScript与多个接口不工作

C# ObjectForScript与多个接口不工作,c#,javascript,winforms,interface,comvisible,C#,Javascript,Winforms,Interface,Comvisible,我有一个WinForm,它通过ObjectForScript与WebBrowserControl交互。WinForm的基类不可见,我无法或不会更改它。因为有一个不可见的基类,所以我创建了一个接口并将其设置为ComVisible(true),并设置FormAttribute[ClassInterface(ClassInterfaceType.None)]。JavaScript可以调用接口中的方法。它工作得非常完美: //Make the class visible for COM so we ca

我有一个WinForm,它通过ObjectForScript与WebBrowserControl交互。WinForm的基类不可见,我无法或不会更改它。因为有一个不可见的基类,所以我创建了一个接口并将其设置为ComVisible(true),并设置FormAttribute[ClassInterface(ClassInterfaceType.None)]。JavaScript可以调用接口中的方法。它工作得非常完美:

//Make the class visible for COM so we can set the ObjectForScripting
//Specify ClassInterfaceType.None to use the ComVisible Interface
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public partial class GeekBrowser : GeekBasePage, IMapControlInteractable
...
public class GeekBasePage : System.Windows.Forms.Form
...
[ComVisible(true)]
public interface IMapControlInteractable
但现在我的问题来了。该接口包含多个函数。我想为单独的任务分组分离接口。所以我想要一个包含日志函数和数据访问函数等的接口

所以它会是这样的:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public partial class GeekBrowser : GeekBasePage, IDataAccess, ILogging
...
public class GeekBasePage : System.Windows.Forms.Form
...
[ComVisible(true)]
public interface IDataAccess
...
[ComVisible(true)]
public interface ILogging
但是当我这样做时,第二个接口(iLogg)的函数无法从Javascript访问。如果我切换接口的顺序,IDataAccess功能将无法访问

因此,似乎只有来自第一个接口的方法才能在Javascript中访问

如何使每个接口的每个功能都可访问?同样,使基类ComVisible和删除ClassInterface属性将起作用,但不是一个选项


提前谢谢

在执行类似项目时,我们发现JavaScript只能访问generate COM包装器的默认接口,在您的情况下,它会选择找到的第一个ComVisible接口作为默认接口,因为您没有显式设置默认接口属性。问题是JavaScript没有类似的查询接口

为了访问其他接口,我们需要为JavaScript创建我们自己的QueryInterface版本,或者在默认接口中提供一个显式的cast类型函数(不是那么优雅),或者使用一个单独的对象来执行到正确的ComVisible接口类型的转换

希望有帮助