0

我收到 StyleCop 的 CA1017 错误消息,说我需要将其设为 ComVisible 为假。

Error   18  CA1017 : Microsoft.Design : 
Because 'NationalInstruments.Labview.FPGA.ModelsimCommunicator.dll' exposes externally 
visible types, mark it with ComVisible(false) at the assembly level and then mark all 
types within the assembly that should be exposed to COM clients with ComVisible(true).

然后,我将代码放在[assembly: ComVisible(false)]最顶层的命名空间之前。但是,我仍然收到相同的错误以及其他错误消息。

Error   19  The type or namespace name 'ComVisible' could not be found (are you 
missing a using directive or an assembly reference?)    


Error   20  The type or namespace name 'ComVisibleAttribute' could not be found (are
you missing a using directive or an assembly reference?)    

似乎VS2010也不识别这个名字。

在此处输入图像描述

这有什么问题?

4

1 回答 1

3

是在命名空间ComVisibleAttribute中定义的。System.Runtime.InteropServices

所以你要么需要:

  1. 使用其命名空间完全限定属性的名称:

    [assembly: System.Runtime.InteropServices.ComVisible(false)]
    
  2. using指令添加到源文件的顶部以导入该文件的命名空间:

    using System.Runtime.InteropServices;
    

将来,您应该能够让 Visual Studio 就这些事情向您发出警告。当您看到表示编译器错误的波浪线时,查找附近的下拉按钮或按Ctrl+.应该会出现一个菜单,指示可能的问题解决方案。在这种情况下,它会建议您选择上面列出的选项 1 或 2,并且只需单击一下,就会为您执行所有必要的操作。

     

(上面惊人的动画图像是从这里撕下来的。)

于 2011-05-24T15:24:35.643 回答