Javascript COM->;。NET-can';t访问重载方法

Javascript COM->;。NET-can';t访问重载方法,javascript,interop,com-interop,typelib,Javascript,Interop,Com Interop,Typelib,我正在尝试从COM(jscript)访问.Net库 我尝试了IDispatch和类接口生成,以及[ClassInterface(ClassInterfaceType.AutoDual)]对所讨论的类 有一个方法有3个重载: Bitmap Build(object, ResizeSettings settings) void Build(object source, object dest, string settings) void Build(object source, object des

我正在尝试从COM(jscript)访问.Net库

我尝试了IDispatch和类接口生成,以及[ClassInterface(ClassInterfaceType.AutoDual)]对所讨论的类

有一个方法有3个重载:

Bitmap Build(object, ResizeSettings settings)
void Build(object source, object dest, string settings)
void Build(object source, object dest, ResizeSettings settings)
召唤

Build("file",s); //works
以下两种情况都会生成“错误数量的参数或无效的属性分配”(JScript运行时错误)

我找不到重载不能通过互操作工作的任何理由,特别是当arg计数不同时。 我错过什么了吗

更新:这里是方法定义的完整代码。第二个过载是不可能的。不仅仅是这些方法——在每个重载方法中,我似乎只能访问第一个重载。这是一个未记录的COM错误/设计缺陷吗

    /// <summary>
    /// Provides methods for generating resized images, and for reading and writing them to disk.
    /// Use ImageBuilder.Current to get the current instance (as configured in the application configuration), or use ImageBuilder.Current.Create() to control which extensions are used.
    /// </summary>
    public class ImageBuilder : AbstractImageProcessor, IQuerystringPlugin
    {


        /// <summary>
        /// Resizes and processes the specified source image and returns a bitmap of the result.
        /// This method assumes that transparency will be supported in the final output format, and therefore does not apply a matte color. Use &amp;bgcolor to specify a background color
        /// if you use this method with a non-transparent format such as Jpeg.
        /// </summary>
        /// <param name="source">May be an instance of string (a physical path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream.</param>
        /// <param name="settings">Resizing and processing command to apply to the.</param>
        public virtual Bitmap Build(object source, ResizeSettings settings) {
            BitmapHolder bh = new BitmapHolder();
            Build(source, bh, settings);
            return bh.bitmap;
        }

        /// <summary>
        /// Resizes and processes the specified source image and stores the encoded result in the specified destination. 
        /// </summary>
        /// <param name="source">May be an instance of string (a physical path or app-relative virtual path), VirtualFile, IVirtualBitmapFile, HttpPostedFile, Bitmap, Image, or Stream. app-relative virtual paths will use the VirtualPathProvider system</param>
        /// <param name="dest">May be a physical path (string), or a Stream instance. Does not have to be seekable.</param>
        /// <param name="settings">Resizing and processing command to apply to the.</param>
        public virtual void Build(object source, object dest, ResizeSettings settings) {
            ResizeSettings s = new ResizeSettings(settings);
//
///提供用于生成已调整大小的图像以及将其读取和写入磁盘的方法。
///使用ImageBuilder.Current获取当前实例(在应用程序配置中配置),或使用ImageBuilder.Current.Create()控制使用哪些扩展。
/// 
公共类ImageBuilder:AbstractImageProcessor,IQuerystringPlugin
{
/// 
///调整并处理指定的源图像,并返回结果的位图。
///此方法假定最终输出格式支持透明度,因此不应用亚光颜色。请使用&;bgcolor指定背景颜色
///如果将此方法与非透明格式(如Jpeg)一起使用。
/// 
///可以是字符串(物理路径)、虚拟文件、IVirtualBitmapFile、HttpPostedFile、位图、图像或流的实例。
///要应用于的调整大小和处理命令。
公共虚拟位图生成(对象源、大小设置){
BitmapHolder bh=新的BitmapHolder();
构建(源、bh、设置);
返回bh.bitmap;
}
/// 
///调整和处理指定的源图像的大小,并将编码结果存储在指定的目标中。
/// 
///可能是字符串(物理路径或应用程序相对虚拟路径)、VirtualFile、IVirtualBitmapFile、HttpPostedFile、位图、图像或流的实例。应用程序相对虚拟路径将使用VirtualPathProvider系统
///可以是物理路径(字符串)或流实例。不必是可查找的。
///要应用于的调整大小和处理命令。
公共虚拟空生成(对象源、对象目标、大小设置){
ResizeSettings s=新的ResizeSettings(设置);

重载不适用于COM的互操作层。但是,您可以使用可选参数并隐藏COM层的所有其他方法:

// COM won't see this.
[ComVisible(false)]
void Test(string a) 

// COM will see this and parameter b is not required
void Test(string a, [DefaultParameterValue(null)] string b)  

重载不适用于COM的互操作层。但是,您可以使用可选参数并隐藏COM层的所有其他方法:

// COM won't see this.
[ComVisible(false)]
void Test(string a) 

// COM will see this and parameter b is not required
void Test(string a, [DefaultParameterValue(null)] string b)  
确实,COM不会“执行”方法重载

但是,看

这是FxCop上的一个文档页面,FxCop是一个静态分析工具。但是这里有一些对COM开发人员有用的信息:

当重载方法向COM客户端公开时,只有第一个方法重载保留其名称。随后的重载通过在名称后附加下划线字符“\u1”和与重载声明顺序相对应的整数进行唯一重命名

另请参见

因此,通过COM层,您可以使用

Build_2("file", "file", s);
Build_3("file", "file", settings);
确实,COM不会“执行”方法重载

但是,看

这是FxCop上的一个文档页面,FxCop是一个静态分析工具。但是这里有一些对COM开发人员有用的信息:

当重载方法向COM客户端公开时,只有第一个方法重载保留其名称。随后的重载通过在名称后附加下划线字符“\u1”和与重载声明顺序相对应的整数进行唯一重命名

另请参见

因此,通过COM层,您可以使用

Build_2("file", "file", s);
Build_3("file", "file", settings);

我认为COM组件的代码(或者至少是接口)更重要的是…你能发布吗?组件是.NET,调用者是COM。我会添加更多代码。我不明白。jscript不是COM。它可以很容易地调用COM组件。如果你希望.NET组件可以作为COM组件访问,你必须为此向.NET组件添加代码(如
ClassInterface)(ClassInterfaceType.AutoDual)
您在问题中谈论的内容)。这使.NET组件成为COM服务器。请发布在.NET组件上定义COM接口的代码。它可能有问题。此外,我记得过去在COM接口中重载方法时遇到问题。您可能希望尝试将该方法重命名为其他方法并调用它。我认为您的COM组件(或至少是接口)在这里更重要…你能发布吗?组件是.NET,调用方是COM。我将添加更多代码。我不明白。jscript不是COM。它可以轻松调用COM组件。如果你想让你的.NET组件作为COM组件访问,你必须为此向.NET组件添加代码(如
ClassInterface(ClassInterfaceType.AutoDual)
您在问题中所说的内容)。这使.NET组件成为COM服务器。发布您在.NET组件上定义COM接口的代码。它可能有问题。此外,我记得过去我在COM接口中重载方法时遇到问题。您可能想尝试将该方法重命名为其他方法并调用它。好主意!一定是这样虽然.NET2兼容,但它是一个库。也许我必须公开一个备用接口。我在.NET2.0应用程序中使用了同样的想法。