无法嵌入互操作类型 'ObjectPickerHelper2Lib.ADObjectPickerClass'。改用适用的接口

Interop type 'ObjectPickerHelper2Lib.ADObjectPickerClass' cannot be embedded. Use the applicable interface instead

我有一个 Visual C++ COM 项目需要添加到我的 C# WinForm 项目中。

我已经将库添加到我的项目中,并且正确添加了 Interop 包装器,但是当我构建时,出现此错误:

error CS1752: Interop type 'ObjectPickerHelper2Lib.ADObjectPickerClass' cannot be embedded. Use the applicable interface instead.
error CS0143: The type 'ObjectPickerHelper2Lib.ADObjectPickerClass' has no constructors defined

出现问题的代码行是:

ObjectPickerHelper2Lib.IADObjectPicker picker = new ObjectPickerHelper2Lib.ADObjectPickerClass();

当我右键单击 ADObjectPickerClass 并选择 "Go to definition" 选项时,显示如下:

#region Assembly Interop.ObjectPickerHelper2Lib.dll, v1.0.0.0
// C:\WorkingFolder\Proyectos\OmniLogin\OmniMaster\obj\Debug\Interop.ObjectPickerHelper2Lib.dll
#endregion

using System;
using System.Runtime.InteropServices;

namespace ObjectPickerHelper2Lib
{
    [ClassInterface(0)]
    [Guid("E064BB22-22CE-4E01-BB63-10EF4058CAF9")]
    [TypeLibType(2)]
    public class ADObjectPickerClass : IADObjectPicker, ADObjectPicker
    {
        public ADObjectPickerClass();

        [DispId(10)]
        public virtual dynamic ADObjectsColl { get; }
        [DispId(7)]
        public virtual string ComputerName { get; set; }
        [DispId(6)]
        public virtual uint DownLevelFilterFlags { get; set; }
        [DispId(8)]
        public virtual uint InitInfo_OptionFlags { get; set; }
        [DispId(2)]
        public virtual uint ScopeFlags { get; set; }
        [DispId(1)]
        public virtual uint ScopeTypeFlags { get; set; }
        [DispId(3)]
        public virtual uint UplevelFilterFlags_Both { get; set; }
        [DispId(4)]
        public virtual uint UplevelFilterFlags_Mixed { get; set; }
        [DispId(5)]
        public virtual uint UplevelFilterFlags_Native { get; set; }

        [DispId(9)]
        public virtual void InvokeDialog(int hWnd);
    }
}

更重要的是,Intellisense 确实显示了 class 构造函数。我正在使用 VS 2012。

任何帮助将不胜感激 谢谢

海梅

我发现这是因为添加 COM 引用时,引用的属性将 Embeded Interop Types 设置为 True。我改成 False 就成功了。